SQL 中得到exec字符串的值
declare @re varhcar(10),@sql nvarchar(1000)
SET @sql = N'SELECT @re = count(*) FROM TableName'
EXEC sp_executesql @sql,N'@re varhcar(10) output',@re output
print @re
我的例子:
DECLARE @strSQL nvarchar(500)
DECLARE @ColuName nvarchar(200)
set @strSQL='Select @ColuName=(SELECT top 1 Question FROM indagate WHERE IndagateID=1'
EXEC sp_executesql @strSQL,N'@ColuName nvarchar(500) output',@ColuName output

浙公网安备 33010602011771号