Solved

CONCAT a fields if one field is NULL

Posted on 2006-11-24
10
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
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 500 total points
ID: 18036570
then you have an older version of Mysql...

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

627 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