quotename 在 exec 中不起作用吗? [英] doesn't quotename work inside of exec?
本文介绍了quotename 在 exec 中不起作用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试做类似于这个问题一>.答案建议在 exec 中使用 quotename.
I'm trying to do something similar to this question. The answer recommends using quotename inside of an exec.
类似:
declare @var nvarchar(128)
set @var = 'hello world'
exec('print ''' + quotename(@var) + '''')
但这不起作用('quotename' 附近的语法不正确).答案错了吗?
But this doesn't work (Incorrect syntax near 'quotename'). Is the answer wrong?
我知道我可以先生成字符串,将其放入一个变量中,然后将其与 exec sp_executeSql
一起使用,但是如果它可以工作,我宁愿按照问题中的方式进行...
I know I can generate the string first, put it in a variable then use it with exec sp_executeSql
, but I would rather do it the way in the question if it can work...
推荐答案
我能想出的最佳解决方案是预先引用值:
Best solution I could come up with for you is to pre-quote the value:
declare @var nvarchar(128);
set @var = 'hello world';
declare @quoted varchar(100);
select @quoted = quotename(@var);
exec('print ''' + @quoted + '''');
这篇关于quotename 在 exec 中不起作用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文