Format SQL string problem with single quote

  • Working with SQL server 2000 in a stored procedure.

    I'm trying to format SQL so that I can execute this SQL in a stored procedure.

    SET @SQL = N'UPDATE TblPostAcademicEducation set ' + @col + ' = ''' + @record + ''' where formResultID = ' + @FRID

    @col is the name of a column, comes from a cursor

    @record is the value of a certain record in that column

    @FRID is an ID column

    The problem I'm facing is that the value of @record (string) sometimes contains a single quote, resulting in an error when I try to format the string.

    I have been googling a lot, but cannot find the exact same problem I have.

    Found a replace option, would be something like replace(@record, ''', ''''), that I should replace a single quote with two single quotes, but that doesn't seem to do the trick.

    Does anyone have an idea on how the resolve this?

    Thanks.

    Vera

  • Use replace(@record,'''','''''')


    Madhivanan

    Failing to plan is Planning to fail

  • Thank you, that works.

  • Vera (10/22/2008)


    Thank you, that works.

    welcome 🙂


    Madhivanan

    Failing to plan is Planning to fail

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

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