concatenating results from SQL query and NULL columns
Posted
by Curtis
on Stack Overflow
See other posts from Stack Overflow
or by Curtis
Published on 2010-05-11T14:54:09Z
Indexed on
2010/05/11
15:14 UTC
Read the original article
Hit count: 247
I need to concatenate several columns of a table into a single value, then show that value in an asp dropdownlist. The SQL code I'm issuing is as follows:
SELECT UserID, CustomerNum, UserName + ' - ' + UserAddress + ',' + UserCity + ' ' + UserState AS UserInfo FROM Users WHERE (CustomerNum = @CustomerNum) ORDER BY UserName
I then set 'UserInfo' as the text field in the dropdownlist.
This generally works, except occasionally one of the columns in the database is null (for example, UserState). When that happens, the entire concatenation is null, and I get an empty entry in the dropdownlist.
Is there something in SQLServer that will allow me to ignore those NULL results, or will I have to code something up in the DataBind event?
Thanks
© Stack Overflow or respective owner