我有动态表,所以我需要执行此查询
DECLARE @SQL nvarchar(max)
SET @SQL = 'select x, y from exTable where z like 'example' '
EXEC (@SQL)
我有问题因为'example'无法添加到@sql变量中。
我尝试添加&示例&但它不起作用。
任何建议如何更改& an; - > “
答案 0 :(得分:2)
您可以在SQL中引用引号:
SET @SQL = 'select x, y from exTable where z like ''example'' '