Tip of the week
Here I will post some tips which you can use while developing your applications.
First Tip, which I got from Weekly Newsletter, copy-pasting for you !
Use of COALESCE function instead of long CASE WHEN … ELSE
(TSQL – MS SQL Server 2000/2005)
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
ELSE ''END
FROM ...
Now lets rewrite the code above using COALESCE function:
SELECT TheSource =
COALESCE (localSource, intranetSource, '')
FROM ...
This will save the lines of code we will write for the query.
No trackbacks yet.