I’ve got a query that looks a bit like this:
select
records.id,
contacts.name + ' (' + contacts.organization + ')' as contact,
from records
left join contacts on records.contact = contacts.contactid
Problem is – contacts.organization is frequently empty, and I get contacts like “John Smith ()”. Is there a way to only concatenate the organization if it’s non-empty?
Use a CASE statement
You could modify it to also check for NULL values, but I do not believe you have that issue because if you had a NULL in your contacts.organization, your entire result field would be null instead of blank.