Instead of using long "SELECT ... CASE WHEN ... ELSE ..." construction, you can use the COALESCE function when you need to find a value that is not NULL. Lets review the following T-SQL expression, in which we need to select an available "source":
SELECT TheSource =
CASE
WHEN localSource IS NOT NULL THEN localSource
WHEN intranetSource IS NOT NULL THEN intranetSource
WHEN internetSource IS NOT NULL THEN internetSource
ELSE ''
END
FROM ...
Now lets rewrite the code above using COALESCE function:
COALESCE(localSource, intranetSource, internetSource, '')
The tip applies to MS SQL Server 2000/2005.
Same tip applies to C#: var TheSource = localSource ?? intranetSource ?? internetSource ?? "";
murki 1/12/2010 11:55:20 PM
Thanks!
Cindy 4/1/2010 12:39:33 AM