Home Forums SQL Server 2008 SQL Server Newbies Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value 'Noida' to data type int. RE: Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value 'Noida' to data type int.

  • Two definite issues:

    1. You have to watch your data types. In your CASE expression your default case outputs a 0, which will default to an INT in SQL Server. Try putting the 0 in single quotes so SQL Server views it as a string-literal.

    2. The ending command for an explicit transaction is not END, it is COMMIT TRANSACTION.

    BEGIN TRANSACTION;

    Declare @b-2 varchar(100);

    SET @b-2 = 'Nodia';

    Declare @D varchar(100);

    SET @D = 'Delhi';

    Update employee

    SET city =(Case

    WHEN city = 'Agra' THEN @b-2

    WHEN city = 'London' THEN @D

    ELSE '0'

    END);

    COMMIT TRANSACTION;

    One potential issue:

    1. Do you need a WHERE-clause? Your update statement will update all rows in the table. Are you sure that is what you want?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato