How to Select table without null value

  • Hi,

    I have a table there are three columns:

    1. Id_Pk

    2. Emp_Name

    3. Salary

    Some Salary fields have Null, Now i want to select table data in such a way that where salary is null there should show '0'. I want result only in one query.

    Tell me abt this problem.

    Regards

    Sarvesh kumar gupta

  • Sarvesh Kumar Gupta (3/13/2008)


    Hi,

    I have a table there are three columns:

    1. Id_Pk

    2. Emp_Name

    3. Salary

    Some Salary fields have Null, Now i want to select table data in such a way that where salary is null there should show '0'. I want result only in one query.

    Tell me abt this problem.

    Regards

    Sarvesh kumar gupta

    select

    Id_Pk,

    Emp_Name,

    coalesce(Salary, 0) as Salary

    from

    dbo.MySalaryTable

  • Hi,

    Thanx, This is working right. what do you tell me abt coalesce().

    Sarvesh:)

  • Read BOL (Books Online), it will provide you all the info you are asking.

    😎

  • coalesce: This function checks all the columns specified in the function and returns the column value which is not null. Simply we can say Returns the first nonnull expression among its arguments

  • select Id_Pk,Emp_Name,isnull(Salary, 0) as Salary from dbo.MySalaryTable

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply