Converstion Error Message in Update Statement

  • (sorry that I posted in the wrong place; can't seem to find how to change categories or delete)

    SQL Server 2008 R2

    table with various columns including M_STATE nvarchar(50) and State varchar(50)

    Some U.S. state values have a comma so I am trying to update the values. Both State and M_STATE have the same data.

    Query:

    UPDATE FORUM_Seneca_MEMBERS

    SET State = LEFT(State, LEN(State - 1)), M_STATE = LEFT(M_STATE, LEN(M_STATE - 1))

    WHERE (RIGHT(State, 1) = ',') AND (LEN(State) = 3)

    Error:

    Error Source: .Net SqlClient Data Provider

    Error Message: Conversion failed when converting the varchar value 'NJ,' to data type int.

  • Check your 'State - 1' bit - you are performing arithmetic rather than subtracting one from the length. You need to rejig your brackets and all should be well.


  • Thanks Phil. Funny how no matter how much you stare at a query you don't see the obvious.

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

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