拼串的时候用char(39) 代替单引号,char(37)代替%,如:
DECLARE @sql VARCHAR(200)
DECLARE @str VARCHAR(200)
SET @str ='bird'
SET @sql = 'SELECT * FROM Category WHERE Name LIKE '+char(39)+char(37)+@str+char(37)+char(39)
EXEC(@sql)
DECLARE @str VARCHAR(200)
SET @str ='bird'
SET @sql = 'SELECT * FROM Category WHERE Name LIKE '+char(39)+char(37)+@str+char(37)+char(39)
EXEC(@sql)