You must Sign In to post a response.
  • Category: SQL Server

    Conversion failed when converting the varchar value 'Null' to data type int.

    Deptid Deptname Employeeid Salary Commission
    10 Sales 1 23000 10000
    20 Accounts 2 18000 0
    30 Purchase 3 32000 Null
    40 Finance 4 25000 0
    50 IT 5 35000 Null

    i want to update salary 10% where comission is null or 0

    i have tried this query it shows error

    UPDATE [deaprtmenttest] SET Salary = (Salary * 10) /100 WHERE Commission in ('Null',0)

    when i execute the above query shows error

    Conversion failed when converting the varchar value 'Null' to data type int.

    how to solve this error
  • #770009
    Hi Rao,

    You should use ISNULL(Commission,0) instead of Commission in ('Null',0). So your updated query will be like below.
    UPDATE [deaprtmenttest] SET Salary = (Salary * 10)/100 WHERE ISNULL(Commission,0) = 0

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


  • Sign In to post your comments