This is my very first T-SQL question, so I hope I'm not using the wrong terminology. I just learned some basic stored procedures and variable declaration, however there is something I haven't understood.
DECLARE @CurrentDate DATETIME
SET @CurrentDate = GETDATE()
select @CurrentDate
-----------------------
2013-09-25 18:47:07.547
(1 row(s) affected)
If I running the above in two batches ( declare
and set
together, select
after) I get:
DECLARE @CurrentDate DATETIME
SET @CurrentDate = GETDATE()
Command(s) completed successfully.
select @CurrentDate
Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@CurrentDate".
It must probably be simple but I couldn't find a solution...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…