我有下一个脚本示例:
DECLARE @lCode INT
DECLARE @lText VARCHAR(400)
DECLARE @lConditionName VARCHAR(40)
DECLARE @Aux VARCHAR(400)
SET @lCode = 1234;
SET @lConditionName = 'Code'
SET @Aux = '@l' + @lConditionName
SET @lText = 'SELECT * FROM Table WHERE Code = ' + @Aux
PRINT @lText
结果是:
SELECT * FROM Table WHERE Code = @lCode
我如何能够像这样了解@Aux Var的价值?
SELECT * FROM Table WHERE Code = 1234
答案 0 :(得分:3)
DECLARE @lCode INT
DECLARE @lText NVARCHAR(400)
DECLARE @lConditionName NVARCHAR(40)
DECLARE @Aux NVARCHAR(400)
SET @lCode = 1234;
SET @lConditionName = N'Code'
SET @Aux = N'@l' + @lConditionName
SET @lText = N'SELECT * FROM Table WHERE Code = ' + @Aux
PRINT @lText
EXEC sp_executesql @lText, N'@lcode INT', @lcode
答案 1 :(得分:0)
你可以试试这个:
DECLARE @lCode INT
DECLARE @lText NVARCHAR(400)
DECLARE @lConditionName NVARCHAR(40)
DECLARE @Aux NVARCHAR(400)
SET @lCode = 1234;
SET @lConditionName = N'Code'
SET @Aux = N'@l' + @lConditionName
SET @lText = N'SELECT * FROM Table WHERE Code = ' + @Aux
set @lText = N'Print ' + @Aux
print @lText
EXEC sp_executesql @lText, N'@lcode INT', @lcode
<强>输出强>
Print @lCode
1234