Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    205

    Unanswered: escaping single quotes

    Hi,

    I need to have an varchar value with single quotes. For eg: the below code throws compilation error.

    Declare @val VARCHAR(20)
    SELECT @val = ''+name+''
    print @val

    Error: Invalid column 'name'


    I want to print name enclosed with single quotes. Please guide me.

    Regards,
    Sam

  2. #2
    Join Date
    Feb 2004
    Posts
    492
    Declare @val VARCHAR(20)
    SELECT @val = 'Kaiowas'
    PRINT @VAL

    EDIT (added): SET @VAL = @VAL + '''Kaiowas'''
    EDIT (added): PRINT @VAL

    SET @VAL = @VAL + '''' + @VAL + ''''
    PRINT @VAL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •