Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to destroy/discard/remove/GC a local variable?

Status
Not open for further replies.

Qik3Coder

Programmer
Jan 4, 2006
1,487
US
Haven't had to do this before, but I'm going to be pasting together a lot of snippets, in which I regularly use the same variable names.

Is there a way to remove a variable once I'm done with it, so the system doesn't freak out when I re-declare it 3 lines later?

TIA,
Lodlaiden

You've got questions and source code. We want both!
 
I wouldn't take that approach myself, I'd do a re-write to bring the snippets together, however, you should just be able to set the value of a variable to NULL at the end of a snippet and just not re-declare it.

Rhys

"Technological progress is like an axe in the hands of a pathological criminal"
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe"
Albert Einstein
 
What I've potentially got is code that may/may not have run as part of a "psuedo batch" script.

Horribly contrived sample:
Code:
if Exists(select 1)
 begin
  declare @tick int
  select @tick = 0
 end

if exists(select 1)
begin
 declare @tick int
 select @tick = 0
end

You've got questions and source code. We want both!
 
I would declare this variable globally for the SP:
Code:
 declare @tick int
 select @tick = 0

if Exists(select 1)
 begin
   -- Some code
 end

if exists(select 1)
begin
   -- Other code
end

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top