Kevin,
Magnus was referring to the entry in BOL about the scope being contained within BEGIN/END blocks. In BOL, search on variables, then click on the "declaring" topic ...down about mid-way thru the topic, under remarks is this:
The scope of a local variable is the batch, stored procedure, or statement block in which it is declared. For more information about using local variables in statement blocks, see Using BEGIN...END.
Which is what Magnus posted in his reply. And why it doesn't seem to work according to the BOL is anybody's guess. <g>
~~Bonnie
>Hey, Magnus/Bonnie,
>
>In BOL, if you search on "local variables" and select the 2nd topic (Transact-SQL variables), you'll find the following:
>
>
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. For example, this script generates a syntax error because the variable is declared in one batch and referenced in another: >
>
>DECLARE MyVariable INT
>SET @MyVariable = 1
>GO
>
>
>
>
>SELECT *
>FROM Employees
>WHERE EmployeeID = @MyVariable
>
>
>Was there a specific topic that indicated something different?
>
>Thanks,
>Kevin