Join Us On Facebook

Please Wait 10 Seconds...!!!Skip

Tuesday, 23 April 2013

Using of COALESCE() and ISNULL() in Sql Server


COALESCE() function -The COALESCE function returns the first non-NULL value from a provided list of expressions. The COALESCE function is passed an undefined number of arguments and it tests for the first nonnull expression among them.If all arguments are NULL then COALESCE returns NULL.

The syntax is as follows:

COALESCE(expression [,...n])

Suppose we have 'employee' table with some data-

we can see that there are some null in mobile column and some null in phone column, so if we need contact details of employee,it may be mobile or phone(if mobile is null then phone and if both are null then it will return null)
so In this case we have to use COALESCE function.

After executing this query, we have found this result-


this is all about COALESCE() function , now Let's discuss about ISNULL() function-

ISNULL() function-
ISNULL validates if an expression is NULL, and if so, replaces the NULL value with an alternate value. In this example, any NULL value will be replaced with a different value.
Suppose we want to mobile number of employee table, and if any value is null in mobile column then we have to return 'unknown' word in place of null as a alternative value,then we write following query -

The result set is come in this way-


Difference between ISNULL and COALESCE-
  • ISNULL is limited to two arguments but in COALESCE we can use more number of arguments
  • Performancewise COALESCE is faster than ISNULL
  • COALESCE is ANSI SQL standard whereas ISNULL is a proprietary TSQL function
  • Using select ISNULL(NULL, NULL) doesn’t throw error but select COALESCE(NULL, NULL) throw an  error




24 comments:

  1. Excellent blog and it’s totally loaded with valid posts on Java and .Net technology. Consider including RSS feed in your blog, so aspirants like me can follow your blog easily. .Net Training in Chennai|Dot net courses in chennai 

    ReplyDelete
  2. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    python training institute in chennai
    python training in Bangalore
    python training institute in chennai

    ReplyDelete
  3. This is ansuperior writing service point that doesn't always sink in within the context of the classroom. In the first superior writing service paragraph you either hook the reader's interest or lose it. Of course your teacher, who's getting paid to teach you how to write an good essay, 
    Data science training in tambaram
    Data Science training in anna nagar
    Data Science training in chennai
    Data science training in Bangalore
    Data Science training in marathahalli
    Data Science training in btm

    ReplyDelete
  4. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs Training in bangalore

    ReplyDelete
  5. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
    Java Training in Chennai | J2EE Training in Chennai | Advanced Java Training in Chennai | Core Java Training in Chennai | Java Training institute in Chennai

    ReplyDelete
  6. Thanks for sharing such an awesome Information with us

    I Got Job in my dream company with decent 12 Lacks Per Annum salary, I have learned this world most demanding course out there in the current IT Market from the Big Data Training In Bangalore Providers who helped me a lot to achieve my dreams comes true. Really worth trying.

    ReplyDelete
  7. You have made some decent points there. I checked on the web for more info about the issue and found most individuals will go along with your views on this gadgets website.

    ReplyDelete
  8. it is an amazing blog to explore more

    BEST ANGULAR JS TRAINING IN CHENNAI WITH PLACEMENT

    https://www.acte.in/angular-js-training-in-chennai
    https://www.acte.in/angular-js-training-in-annanagar
    https://www.acte.in/angular-js-training-in-omr
    https://www.acte.in/angular-js-training-in-porur
    https://www.acte.in/angular-js-training-in-tambaram
    https://www.acte.in/angular-js-training-in-velachery


    ReplyDelete
  9. I enjoyed by reading your blog post. Your blog gives us information that is very useful for us, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again. You can use this for any quantum realm white jacket kind of academic writing work.



    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery



    ReplyDelete

  10. I appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog. Best of luck

    Java training in Chennai

    Java training in Bangalore

    Java training in Hyderabad

    Java Training in Coimbatore

    Java Online Training

    ReplyDelete
  11. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Python Training in Chennai

    Python Training in Velachery

    Python Training in Tambaram

    Python Training in Porur

    Python Training in Omr
    Python Training in Annanagar

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Great post. keep sharing such a worthy information.
    Data Science Certification in Chennai

    ReplyDelete