Skip to content
Advertisement

is it possible to do a conditional concat?

I have a query that pulls different data but for one field it concats its since the URL is partially filled in my db

select blah, blah2, blah3, concat('https://my_url.com', g.logourl ) as logourl

but the problem is if logourl is blank then I just get https://my_url.com instead of the full URL. This is having down stream impact.

Is there a way to only concat if logurl is not null?

Advertisement

Answer

You can try using case when expression

select blah, blah2, blah3, 
 case when g.logourl is not null and g.logourl<>''
     then concat('https://my_url.com', g.logourl ) end as logourl
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement