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
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.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: