Follow us: Connect on YouTube Connect on YouTube Connect on YouTube

Pages

Friday, 1 April 2016

SQL-Coalesce


This will gives the first non-null string.

    Syntax: coalesce (strng1, string2, string3 … stringn)      

    Ex:
         SQL> select coalesce('a','b','c'), coalesce(null,'a',null,'b') from dual;

COALESCE COALESCE
-----------   -----------
       a                  a



You May Like                                             
                            SQL Abs
                            SQL Sign
                            SQL Sqrt
                            SQL Mod
                            SQL NVL
                            SQL NVL2
                            SQL Power
                            SQL Exp
                            SQL Ln
                            SQL Log
                            SQL CEIL
                            SQL Floor
                            SQL Round
                            SQL Trunc
                            SQL Bitand
                            SQL Greatest
                            SQL Least
                           
Share this article :

2 comments:

  1. Hi There,


    Great info! I recently came across your blog and have been reading along.
    I thought I would leave my first comment. I don’t know what to say except that I have

    We have a linked server "LinkSQL" defined on SQLServerA against the same server, ie, SQLServerA and the server has Named Pipes disabled. Isn't communication among'st applications within one server happens primarily through Named Pipes. If so, would it be better if we have Named Pipes enabled on this SQLServer box?
    We are seeing intermittent TCP/Semaphore errors and I was wondering if enabling this option would help.
    But nice Article Mate! Great Information! Keep up the good work!


    Thank you,
    Reena

    ReplyDelete
  2. Hi There,

    A spot on observation on what probably is “the” underlying details of the SQL-Coalesce .Too many people don’t even think about wherever there will be actual demand and more importantly what happens if this demand comes later (or maybe a lot later) than they expect

    1) How can I amend this select to make a sum & group by a single line....

    SELECT article_ref, status, total_amount
    FROM order_tbl
    GROUP BY article_ref, status, total_amount
    ORDER BY article_ref, status, total_amount;

    tbl_order
    article_ref status total_amount
    123456 Ordered 100
    123456 Ordered 10
    123456 Ordered 80
    123456 Pending 50
    123456 Pending 23
    123456 Pending 50
    123456 Delivered 50
    123456 Delivered 75

    And want the output to be
    123456 Ordered 190
    123456 Pending 123
    123456 Delivered 125









    It was cool to see your article pop up in my google search for the process yesterday. Great Guide.
    Keep up the good work!

    Grazie,
    Tarun

    ReplyDelete