DECLARE语句使变量成为全局变量?

时间:2013-10-22 14:01:10

标签: tsql global-variables sql-server-2012 declare table-variable

为什么DECLARE语句将声明的变量设为全局?

例如:

SET NOCOUNT ON
GO

    DECLARE @LoopCounter TINYINT = 3

    WHILE @LoopCounter <> 0
    BEGIN

        DECLARE @TempDataSource TABLE ([ID] TINYINT)

        SELECT [ID]
        FROM @TempDataSource

        INSERT INTO @TempDataSource ([ID])
        VALUES (1)
              ,(2)
              ,(3)

        SET @LoopCounter = @LoopCounter - 1
    END

SET NOCOUNT OFF
GO

给我:

enter image description here

在所有情况下它都不会返回任何内容吗?

0 个答案:

没有答案