November 4, 2008 at 9:56 pm
hi all
can any one tell me, what is the main usage and advantage of coalesce(). why it is used
thanks in advance
aswin..
November 4, 2008 at 10:13 pm
COALESCE() is used to replace NULLs with another value:
COALESCE(A, B, C, .., Z)
The coalesce function searches through all of the parameters, left to right, and returns the first one that is not NULL. So in this example, it will return the value of A, unless A is Null, in which case it will return the value of B, unless B is also Null, in which case it will return the value of C ... etc., etc.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
November 4, 2008 at 10:19 pm
aswanidutt.dasara (11/4/2008)
hi allcan any one tell me, what is the main usage and advantage of coalesce(). why it is used
thanks in advance
aswin..
Coalesce function recives values separted by column and returns the first value that is not null. I can’t tell you of an advantage of using it, because I don’t know what you want to compare it to. If you have a situation that you can get many values and you need to use the first one that is not null, then you should use it. If you want to read more about coalesc and isnull function there is a good article at
http://databases.aspfaq.com/database/coalesce-vs-isnull-sql.html
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
November 4, 2008 at 10:47 pm
hi all
thanks for the reply
regards
aswin.
November 4, 2008 at 10:51 pm
Glad we could help.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply