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 |
|
Ex
Posting Yak Master
166 Posts |
Posted - 2004-12-13 : 18:44:41
|
| Hello all,i am also wondering if someone could help with global variable creation/modification. I have had trouble finding code i could use in a sql script, could anyone shed some light on this subject for me plzta |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-12-13 : 19:00:32
|
| Global variables:DECLARE @@Global1 intLocal variables:DECLARE @Local1 intSET @@GLOBAL1 = 1SET @Local1 = 2Tara |
 |
|
|
Ex
Posting Yak Master
166 Posts |
Posted - 2004-12-13 : 19:10:29
|
| thanks for the quick response tduggan but i am am still having problems i tried to run a exampleDECLARE @@myglobal intSET @@myglobal = 1gocreate PROCEDURE test1asSET @@myglobal = @@myglobal + 1and i get the errorMust declare the variable '@@myglobal'. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-12-13 : 19:41:50
|
| Well you didn't declare it. CREATE PROCEDURE test1ASDECLARE @@myglobal intSET @@myglobal = @@myglobal + 1GOI would read up in SQL Server Books Online on stored procedures or get yourself a good book.Tara |
 |
|
|
Ex
Posting Yak Master
166 Posts |
Posted - 2004-12-13 : 19:56:37
|
| Sorry i may of given the wrong meaning,i would like to create global variables that have their scope outside of all stored procedures i.e that are database wide but i am not sure how to do it or if you can do itcreate PROCEDURE test0ASDECLARE @@myglobal intSET @@myglobal = 1gocreate PROCEDURE test1asSET @@myglobal = @@myglobal + 1goSELECT @@myglobal |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-12-13 : 19:57:12
|
| Ummmm...there is no such thing as a global variable in T-SQL. All variables are local to the procedure or function in which they're declared. You'd either have to pass the variable from one procedure to another or store its value in a table where it can be retrieved later. |
 |
|
|
Ex
Posting Yak Master
166 Posts |
Posted - 2004-12-13 : 20:00:17
|
| :) ta that was plan B,sorry wasn't to sure if there was the option of a 'global' or not thanks for the quick response |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-12-13 : 20:38:40
|
Does this do it?CREATE PROCEDURE CreateGobalASDECLARE @@myglobal intWHILE 1=1BEGIN WAITFOR TIME '01:00'ENDGO Kristen |
 |
|
|
|
|
|