您好:如下语法
DECLARE @ct smallint;
set @SQL = \' DECLARE @ct smallint;select @ct=COUNT(\'+@Field+\') from \' + @Table + \' where \' + @Field + \'=\'\'\' + @XX + \'\'\'\'
print(\'2 --> \' + @SQL)
EXEC sp_executesql @SQL
select @ct
但结果select @ct 却是NULL请问 ,这有办法 捞出他的结果值吗?谢谢
2 个回答
1
纯真的人
iT邦大师 1 级 ‧ 2025-02-08 10:59:44
最佳解答
参考 如何取得 sp_executesql 参数回传值
DECLARE @SQL nvarchar(max)
,@Count int=0;
set @SQL = \'select @CountOut=123456789 \'
declare @CountSetOut nvarchar(max) = \'@CountOut int OUTPUT\'
EXEC sp_executesql @SQL , @CountSetOut , @CountOut = @Count OUTPUT
select @Count "测试资料"
-
1 -
-
noway
iT邦研究生 1 级 ‧
2025-02-11 13:50:44
谢谢您的回覆
这样OK
修改
1
allenlwh
iT邦高手 1 级 ‧ 2025-02-08 09:31:45
set @SQL = \' DECLARE @ct smallint;select @ct=COUNT(\'+@Field+\') from \' + @Table + \' where \' + @Field + \'=\'\'\' + @XX + \'\'\';select @ct as cnt \'