Link to home
Start Free TrialLog in
Avatar of jaycangel
jaycangel

asked on

CONCAT a fields if one field is NULL

I would like to concat two fields

select CONCAT(field1, field2)

if field1 or field2 is NULL then i want it treated as a blank string. I've tried CAST, but it doesn't work. As soon as you have a null in a CONCAT it will not work at all, not even partial.

Thanks
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

select CONCAT(COALESCE(field1,''), COALESCE(field2,''))
In sql server

SELECT ISNULL(field1,'')+ISNULL(field2,'')
In Oracle -
select concat(nvl(field1,''),nvl(field2,''))
in ingres
select concat(ifnull(field1,''),ifnull(field2,'')) from table

in firebird
select coalesce(field1,'') || coalesce(field2,'') from rdb$database

Avatar of jaycangel
jaycangel

ASKER

How can i do it in MySQL?
my initial suggestion works in mysql
but mysql doesn't have COALESCE ?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial