467,915 Members | 1,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

Combine two column with sql statement

Expert 100+
I was able to combine three columns with following sql statement but the problem that i am having is if one of the column has a null value the concatenation does not work and the sql statement does not return any thing. I am not sure why this is happening. Is there a way to accomplish this even though the fields contain null value.

Sql statement:

Expand|Select|Wrap|Line Numbers
  1. Select CAST(Customer.Contactid as nvarchar(10)) +'-'+ Customer.Firstname +','+ Customer.LastName as Name from Customer where customerid = 1547854
Data types:

Contactid -- int
FirstName -- nvarchar
LastName -- nvarchar

Note: The above sql statement works perfect if non of the fields have null value.

Thank you in advance
Sep 9 '08 #1
  • viewed: 6955
Share:
2 Replies
ck9663
Expert 2GB
Yes.

Use ISNULL() function.

Try this:

Expand|Select|Wrap|Line Numbers
  1. Select isnull(CAST(Customer.Contactid as nvarchar(10)),'') +'-'+ isnull(Customer.Firstname,'') +','+ isnull(Customer.LastName,'') as Name from Customer where customerid = 1547854
-- CK
Sep 9 '08 #2
Expert 100+
It worked

Thank you
Sep 9 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by mmccaws | last post: by
9 posts views Thread by Joost Kraaijeveld | last post: by
5 posts views Thread by Jamie Pittman via AccessMonster.com | last post: by
14 posts views Thread by imani_technology_spam | last post: by
5 posts views Thread by Antanas | last post: by
1 post views Thread by chrisbo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.