Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rohcky
Starting Member
38 Posts |
Posted - 2005-04-20 : 15:41:59
|
| Is there a way to do a query on a table and store the data in a global variable?For instance, can I do a select count(some_column) and set a global variable to = that? I can't seem to figure it out and would appreciate some help. |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-04-20 : 16:24:54
|
| I would use a table. Have a trigger make sure it only contains 1 row, and set the values on that row for your global "variables".Why what do you need to store as a global variable?Once you set the "varibale", it is already out of date by the time you set it.Brett8-) |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-04-20 : 17:32:51
|
| What is the big picture objective? There is probably a "sql" way to accomplish it:UDF, Output vars, Return Codes, etc...You can create and set a global variable, you just can't use it outside the scope of a local variable :)declare @@myGlobalVar intset @@myGlobalVar = 10Be One with the OptimizerTG |
 |
|
|
rohcky
Starting Member
38 Posts |
Posted - 2005-04-21 : 13:33:24
|
| I figured it out. Supposed to click parameters>output parameters and set output global variables. The reason I needed to store the count in a global variable is because I'm writing a DTS that loops some number of records. It checks the data and determines which should be delete (through an alogorithm that's too complex to describe) and labels it as 'delete'. Then an 'execute sql task' counts the number of records labeled 'delete' and stores the count in the global variable. Loop stops when there are no more records labeled 'delete' (when global = 0). Thanks for trying though. I should really try harder to figure things out before I post... |
 |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2005-04-22 : 05:13:17
|
| Rohcky - The confusion stems from posting in the wrong forum. The phrase "Global variable" will be interpreted differently in the Developer forum than it would in the DTS forum!Mark |
 |
|
|
|
|
|