C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Difference between ISNULL() and COALESCE().


Posted Date: 09 Apr 2008    Resource Type: Articles    Category: Databases

Posted By: Nitin Srivastava       Member Level: Gold
Rating:     Points: 7



There is very slightly difference between the ISNULL and COALESCE functions.
Both the function Replaces the NULL value with the other specified replacement value but there is a very minor difference between them.

e.g. for ISNULL


DECLARE @var varchar(3)
SET @var = NULL

select ISNULL(@var,'abc')

The out put of this query is 'abc'.

e.g for COALESCE

DECLARE @var varchar(3)
SET @var = NULL

select COALESCE (@var,'abc')

The out put of this query is also 'abc'.

Now i am discussing the difference between them..

The difference is:
"The result of ISNULL() function always takes on the datatype of the first parameter (regardless of whether it is NULL or NOT NULL)
while for COALESCE works, it works like a CASE expression."

The difference between them will be more clear by this example.

DECLARE @var varchar(3)
SET @var = NULL

select ISNULL(@var,'abcdef')

The out put of this query is 'abc'. --as we mention the datatype of @var as varchar of size "3".

----

DECLARE @var varchar(3)
SET @var = NULL

select COALESCE (@var,'abcdef')

The out put of this query is 'abcdef'. -- Regardless the size of the @var.

------

I think now the difference is clear..




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Isnull  .  Difference  .  Coalesce  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Difference between Nested Sub query and Co-related sub query
Previous Resource: Trigger in different version of sqlserver
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

online optimum rewards

Contact Us    Privacy Policy    Terms Of Use