DECLARE @i int = 1; IF @i > 10 BEGIN DECLARE @A int = 100; END PRINT @A; // doesn't return any result
感谢名单
它是每批次/存储过程等
From MSDN(我的大胆)
The scope of a variable is the range of Transact-sql statements that can reference the variable. The scope of a variable lasts from the point it is declared until the end of the batch or stored procedure in which it is declared.