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
I get error when I execute the above code. I see @ID print and it goes away and I get the following messages.
"Must declare the scalar variable "@Key"
"Must declare the scalar variable "@indicator"
"Must declare the scalar variable "@date"
Datatypes in the table: ID = nvarchar(14), key = int, indicator = varchar(1), and date = timestamp