RE: Declaring Variables Dynamically

RE: Declaring Variables Dynamically

 

  

Short answer: I don't think so.

Long answer:
I did some quick testing, and though you can use a while loop to create the
variables, there is an issue with the scope of the variable. In my test, I
created a loop to generate a sql string and execute it with sp_executesql.
The variable can only be used in the context of the sql statement that is
being executed. If I declare all of the variables at once and then try to
use them, they are no longer in scope.

I think you are probably better off just declaring them individually.

Kevin Martin
Database Engineer
Multimedia Games




-----Original Message-----
From: Dave Sueltenfuss [mailto:Dave.[Email Address Removed] Monday, July 28, 2003 11:26 AM
To: LazyDBA.com Discussion
Subject: Declaring Variables Dynamically


Good afternoon,

I need to create 36 variables, @var1 through @var36. Does anyone know if
I can do this dynamically, using a WHILE loop, or should I just declare
each one individually
Any help is appreciated

Thanks

Dave Sueltenfuss
Application Developer
Certified ColdFusion MX Developer
Arch Wireless
Phone: 508-870-6711
Fax: 508-870-8011
Email: dave.[Email Address Removed]


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003

MS Sql Server LazyDBA home page