January 18, 2005 at 9:38 am
Can anyone tell me what the scope of a variable is...for example in an sql script one of the first commands is the declaration of a variable.
However later in the script when I need to use the variable again, I get the usual 'must declare variable' error. How can I get around this other than declaring and setting the variable each time I want to use it (which will obviously defeat the purpose of using a variable in the first place)??
Thanks for your help guys, greatly appreciated.
If riding in a plane is flying, then riding in a boat must be swimming. To experience the element, get out of the vehicle. Skydive!
January 18, 2005 at 10:24 am
If you use GO within the statement then it's going to clean out the variable.
You could just execute the statements without the go and keep the variable.
January 18, 2005 at 6:32 pm
BOL is your friend:
The scope of a local variable is the batch, stored procedure, or statement block in which it is declared.
Mr. or Ms. alluded to the batch, which is separated by the keyword GO.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply