page 1 of 1
Comments: 3 | Views: 1071

I have a SELECT query, in which something like below:-

(SerialNumber.Number + '- ' + SerialNumber.Description) AS SerialNumberInfo

When the SerialNumber.Number is a null value, the SerialNumberInfo will return null value even though SerialNumber.Description contain a value. Is there any solution to change the logic where either field has value will return value AS SerialNumberInfo? Thanks

Take a look at the ISNULL and the COALSESCE functions, they can help you with your problem.
There are a few alternatives to work around the issue. Perhaps the easiest is to translate the null string in the query:

SELECT ISNULL(SerialNumber.Number, '') + '-' + SerialNumber.Description AS SerialNumberInfo

The other alternative is pull the raw data into the query and perform the contatenation in code:

SELECT SerialNumber.Number, SerialNumber.Description

string serialNumberInfo = reader["Number"] as string ?? "" + reader["Description] as string;

There may be other alternatives, but I think these are the easiest to implement.
page 1 of 1
Comments: 3 | Views: 1071