I have a select statement like
SELECT 'Name' = customer_fname+ ', ' + customer_lname
FROM customers
Its output is like:
peter, willson
jenny, Mark
Now, if customer_fname is null, then output will be:
, willson
, Mark
If customer_lname is null then:
peter,
jenny,
And if both customer_fname and customer_lname are null then only the comma will be displayed.
I want to remove the comma. How do I do this?
Ordinarily I would suggest using the ISNULL operator. However, as you need to check on both fields, the logic becomes a bit nasty. Therefore, I would suggest using a CASE statement.
EDIT For dknaack – an ISNULL solution 🙂