CONCAT a fields if one field is NULL

Posted on 2006-11-24
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.

Question by:jaycangel
LVL 142

Expert Comment

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

Expert Comment

by:Aneesh Retnakaran
ID: 18008704
In sql server

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

Expert Comment

ID: 18008791
In Oracle -
select concat(nvl(field1,''),nvl(field2,''))
LVL 19

Expert Comment

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

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

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.


Author Comment

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

Expert Comment

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

Author Comment

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

Accepted Solution

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

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vcenter 6 u2 install question 1 101
report returning null 21 79
Trigger usage 2 59
Hi,İ want to find month which its name have 4 letter.Ex:June,July (in SQL Server 2014) 2 55
Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now