我正在尝试做类似的事情这个问题 https://stackoverflow.com/questions/837358/sql-create-logon-cant-use-parameter-as-username。答案建议在 exec 内部使用 quotename 。
与此类似:
declare @var nvarchar(128)
set @var = 'hello world'
exec('print ''' + quotename(@var) + '''')
但这不起作用(“quotename”附近的语法不正确)。答案有错吗?
我知道我可以先生成字符串,将其放入变量中,然后将其与exec sp_executeSql
,但我宁愿按照问题中的方式来做,如果它可以工作......
我可以为您提供的最佳解决方案是预先引用该值:
declare @var nvarchar(128);
set @var = 'hello world';
declare @quoted varchar(100);
select @quoted = quotename(@var);
exec('print ''' + @quoted + '''');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)