update charecter value to a column int

  • hi

    After modifying a column data type from int to varchar when I try to insert or update any

    existing value with characters it gives me the following error

    Syntax error converting the varchar value 'ABC1' to a column of data type int.

    But the column has been changed from int to varchar.

    Eg :

    Employee table was created with employee type field as int which held values from 1...10

    We had to change this field from int to Varchar.

    Can someone provide help me solve this....

    Thanks in Advance!

    priya

  • Heh... did you convert the correct column? Only way you can get that error is if the target column is actually an INT... double check the schema and make sure.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Maybe it's caused by an un-commited Transaction elsewhere in code run on the same database prior to your alter column code execution.

  • please check the schema and put the details in your reply

  • Hi, This is because even thoguh you converted the data type from char to int, there would be some values which wouldnt have got converted to int. This is a typical scenario when you change a nvarchar datatype col to uniqueidentifier. You need to first run a test on the existing data to check if anyone of those are not converted to int. Convert them / delete and re-enter and then run your queries. This should work.

  • If your getting the problem in select statement i am sure there will be an varchar data in the filed. Check the data.

  • Any chance you're trying to do your insert via a stored procedure that has not been updated to accept a varchar value as of yet?

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

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