because ' is also used to delimit literal strings, if you need to include ' inside the string, you need to use '', so in your case, @where will contain (assume @name is 'abc')where name like '%abc%'
调试欢乐多
select @Where = ' where '
select @Where = @Where + 'name like ''%' + @name+ '%'''
在sql的查選環境中加上
print @where 去看看結果就明白了.