Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CONCAT a fields if one field is NULL

Posted on 2006-11-24
10
Medium Priority
?
497 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 143

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 143

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 143

Accepted Solution

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

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

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

885 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