error

  • Select jobid As job,

    CASE WHEN code in ('1','2','3') THEN code

    ELSE 'Code is wrong' End AS ErrorMessage

    FROM emp where job not in ('1','2','3')

    when i run the above sql statement I am gettign an error

    Msg 245, Level 16, State 1, Line 1

    Syntax error converting the varchar value 'Code is wrong' to a column of data type int.

  • What data type is the code column in your emp table?

    Please Post table definition.

    It is likely your code table is an int.

    Try

    Select jobid As job,

    CASE WHEN code in ('1','2','3') THEN cast(code as varchar(12))

    ELSE 'Code is wrong' End AS ErrorMessage

    FROM emp where job not in ('1','2','3')

Viewing 2 posts - 1 through 1 (of 1 total)

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