Solved

CONCAT a fields if one field is NULL

Posted on 2006-11-24
10
492 Views
Last Modified: 2009-06-24
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
Comment
Question by:jaycangel
10 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18008631
select CONCAT(COALESCE(field1,''), COALESCE(field2,''))
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18008704
In sql server

SELECT ISNULL(field1,'')+ISNULL(field2,'')
0
 
LVL 32

Expert Comment

by:awking00
ID: 18008791
In Oracle -
select concat(nvl(field1,''),nvl(field2,''))
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 19

Expert Comment

by:NickUpson
ID: 18009205
in ingres
select concat(ifnull(field1,''),ifnull(field2,'')) from table

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

0
 
LVL 1

Author Comment

by:jaycangel
ID: 18036041
How can i do it in MySQL?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18036378
my initial suggestion works in mysql
0
 
LVL 1

Author Comment

by:jaycangel
ID: 18036409
but mysql doesn't have COALESCE ?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18036570
then you have an older version of Mysql...

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

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question