Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 498
  • Last Modified:

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
0
jaycangel
Asked:
jaycangel
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
select CONCAT(COALESCE(field1,''), COALESCE(field2,''))
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
In sql server

SELECT ISNULL(field1,'')+ISNULL(field2,'')
0
 
awking00Commented:
In Oracle -
select concat(nvl(field1,''),nvl(field2,''))
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
NickUpsonSenior Network EngineerCommented:
in ingres
select concat(ifnull(field1,''),ifnull(field2,'')) from table

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

0
 
jaycangelAuthor Commented:
How can i do it in MySQL?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
my initial suggestion works in mysql
0
 
jaycangelAuthor Commented:
but mysql doesn't have COALESCE ?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
then you have an older version of Mysql...

select CONCAT(IFNULL(field1,''), IFNULL(field2,''))
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now