Reputation: 31
I have a DropDownList
that is bound to sqlDataSource
. Part of the SQL query is:
"Select (firstName +" "+ SecondName +" "+ LastName) AS Name"
DataTextField
property of the DropDownList
is set to Name
.
The problem is: if any of (firstName
, SecondName
, and LastName
) equal to NULL
, the DataTextField
property become empty.
How can I fix this?
Upvotes: 0
Views: 237
Reputation: 35514
I use something like this. You have to check for NULL values and replace them with an empty string. Finally I replace 2 spaces with 1 in the replace function to account for empty SecondNames.
SELECT REPLACE(ISNULL(firstName, '') + ' ' + ISNULL(SecondName, '') + ' ' + ISNULL(LastName, ''), ' ', ' ') AS Name
Upvotes: 2