Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
HowTo: Release a Table variable
Message
From
13/01/2005 12:57:00
 
 
To
13/01/2005 12:37:07
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
00976391
Message ID:
00976854
Views:
19
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>


Hey, Bonnie,

Thanks, I found the reference. Sorry I didn't catch it before. The plot thickens (or the thought plickens) ;)

It seems BOL is saying two things that don't appear to be fully consistent. What you and Magnus found (under variables...declaring) clearly states that the scope includes statement blocks. What I found under local variables only mentions batches and procs.

I did the same type of test that you ran...
declare @nOuterInt integer
set @nOuterInt =1
if @nOuterInt = 2 
	begin
		declare @nInnerInt integer
		set @nInnerInt = 10
	end
select @nInnerInt
Like yours, it runs without errors, and returns a NULL. If I change nOuterInt to a 2, the query returns 10.

I posted this on one of the MS SQL Newsgroups to see what the folks over there say.

Stay tuned for the exciting conclusion of "As the Variable Burns!"

Kevin
Previous
Reply
Map
View

Click here to load this message in the networking platform