从SQL查询和NULL列串联结果 [英] concatenating results from SQL query and NULL columns
问题描述
我需要连接一个表中的几列到一个单一的值,然后显示在一个asp DropDownList中的价值。在SQL code,我发出如下:
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:
选择用户名,CustomerNum,用户名+' - '+ UserAddress +,+ UserCity +''+ UserState AS的UserInfo
来自用户的
WHERE(CustomerNum = @CustomerNum)
ORDER BY用户名
SELECT UserID, CustomerNum, UserName + ' - ' + UserAddress + ',' + UserCity + ' ' + UserState AS UserInfo FROM Users WHERE (CustomerNum = @CustomerNum) ORDER BY UserName
我然后设置的UserInfo作为在DropDownList文本字段。
I then set 'UserInfo' as the text field in the dropdownlist.
这通常工作,除了偶尔在数据库中的列之一为空(例如,UserState)。当这种情况发生时,整个拼接为空,而我得到在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.
有什么SQLServer中,让我忽略那些空的结果,否则我将不得不code向上的东西在的DataBind事件?
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?
感谢
推荐答案
对于空列做这样的事。
ISNULL(UserState, '')
这篇关于从SQL查询和NULL列串联结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!