Solved

CONCAT a fields if one field is NULL

Posted on 2006-11-24
10
490 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 31

Expert Comment

by:awking00
ID: 18008791
In Oracle -
select concat(nvl(field1,''),nvl(field2,''))
0
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now