Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • What is COALESCE in SQL Server

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 693
    Comment on it


         COALESCE is a function in SQL Server which returns the first non NULL expression amongst its parameter. If all the parameters are evaluated to NULL, It will return NULL



    COALESCE( expression1, expression2, ... expression_n )

    Here expression1 to expression_n are the parameters to COALESCE function. Unlike ISNULL which takes 2 parameter COALESCE can have n parameters


     I am using the below script to create the table

    CREATE TABLE EmpDetail
    Id INT IDENTITY(1,1),
    Name NVARCHAR(20),
    MobileNo NVARCHAR(10),
    PhoneNo NVARCHAR(15),
    AlternateNo NVARCHAR(15)

    and i am using the below sample data

    INSERT INTO EmpDetail VALUES('A','7894561230',NULL,NULL),

    And here is the result



    Here in above query we can see COALESCE function return the first non null values amongst its parameter


 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: