SQL Escape ' '

前端 未结 7 1151
星月不相逢
星月不相逢 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:35

    There are several ways that you can escape character data in SQL Server, some people even advocate the use of the QUOTENAME() functions.

    If you really want to develop of solid understanding of this subject area then may I recommend that you take a look at what experienced SQL Server Developers consider to be essential reading with regard to the different methods you can use to incorporate Dynamic T-SQL into your coding.

    The Curse and Blessings of Dynamic SQL

    0 讨论(0)
提交回复
热议问题