SQLTeam.com | Weblogs | Forums

String ConCat in Case when

Hi,

here is my Query and need help in errormesssage column, when there is multiple column with Null then it should be ' CustomerName is Null; Customer City is Null' or CustomerCity is Null; CustomerCountry is Null' based on all the columns that is Null. this is just sample code in real table it will be checked for around 10-15 columns.

select CustomerID,
CASE when CustomerName IS Null OR
(CustomerCity)IS Null OR
(CustomerCountry) IS Null
then 'Yes' ELSE 'NO'
END as recordvalid,

CASE when CustomerName IS Null Then ' CustomerName IS Null;'
when CustomerCity IS Null Then ' CustomerCity IS Null;'
when CustomerCountry IS Null Then ' CustomerCountry IS Null;'

END errormessage
into #temp
from Customer

thanks

,CASE WHEN CustomerName IS NULL THEN ' CustomerName IS Null;' ELSE '' END
	+ CASE WHEN CustomerCity IS NULL THEN ' CustomerCity IS Null;' ELSE '' END
	+ CASE WHEN CustomerCountry IS NULL THEN ' CustomerCountry IS Null;' ELSE '' END
	AS ErrorMessage
1 Like

thank you, it worked perfectly.