Declare @ID nvarchar(14) = '12345678912345'
DECLARE @Key int = (SELECT key
FROM table
WHERE id = @ID)
Declare @indicator varchar(1) = 'A'
Declare @rdate Datetime = (SELECT LTRIM(RTRIM(Left(CAST(GetDate() AS Datetime2),23))))
SELECT @ID
GO
SELECT @Key
GO
SELECT @indicator
GO
SELECT @date
GO
执行上面的代码时出错。我看到@ID打印,它消失了,我得到以下消息。
“必须声明标量变量”@Key“
“必须声明标量变量”@indicator“
“必须声明标量变量”@date“
表中的数据类型:ID = nvarchar(14),key = int,indicator = varchar(1),date = timestamp
答案 0 :(得分:2)
Go
将结束范围并销毁变量。
使用;
代替
SELECT @ID;SELECT @Key;SELECT @indicator;SELECT @rdate;