SQL Escape ' '

前端 未结 7 1149
星月不相逢
星月不相逢 2021-01-12 22:49

I am trying to run a query in SQL 2008 by doing:

@query varchar(max)

SET @query = \'SELECT * FROM Table WHERE [Name] = \' \'Karl\' \' \'

EXEC(@query)
         


        
7条回答
  •  一生所求
    2021-01-12 23:17

    A double single ('') quote will act like a single single quote when inside a string literal.

    Have you tried using a variable?

    declare @karl_name varchar(10);
    set @karl_name = '''Karl''';
    
    SELECT * FROM Table WHERE [Name] = @karl_name
    

提交回复
热议问题