Reputation: 221
I have a Char(1) Nullable column (District) that I want to output "Not assigned" when NULL;
I've tried
SELECT CASE District
WHEN NULL
THEN 'Not Assigned'
ELSE District
END AS District
,[Name]
,AgencyType
FROM cli_Agency
and
SELECT CASE CONVERT(VARCHAR, District)
WHEN NULL
THEN 'Not Assigned'
ELSE CONVERT(VARCHAR, District)
END AS District
,[Name]
,AgencyType
FROM cli_Agency
But Null is displayed instead of 'Not Assigned'.
Upvotes: 1
Views: 22
Reputation: 81970
Just a syntax issue
...
CASE WHEN District IS NULL THEN 'Not Assigned' ELSE District END AS District,
...
You could also write it as
IsNull(District,'Not Assigned') as District,
Or Even
coalesce(District,'Not Assigned') as District,
Upvotes: 3