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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Global variables SQL server

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 plz

ta

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-12-13 : 19:00:32
Global variables:

DECLARE @@Global1 int

Local variables:

DECLARE @Local1 int

SET @@GLOBAL1 = 1
SET @Local1 = 2

Tara
Go to Top of Page

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 example

DECLARE @@myglobal int
SET @@myglobal = 1
go

create PROCEDURE test1
as
SET @@myglobal = @@myglobal + 1


and i get the error

Must declare the variable '@@myglobal'.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-12-13 : 19:41:50
Well you didn't declare it.

CREATE PROCEDURE test1
AS

DECLARE @@myglobal int

SET @@myglobal = @@myglobal + 1

GO

I would read up in SQL Server Books Online on stored procedures or get yourself a good book.

Tara
Go to Top of Page

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 it

create PROCEDURE test0
AS
DECLARE @@myglobal int
SET @@myglobal = 1
go

create PROCEDURE test1
as
SET @@myglobal = @@myglobal + 1

go

SELECT @@myglobal
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-12-13 : 20:38:40
Does this do it?

CREATE PROCEDURE CreateGobal
AS

DECLARE @@myglobal int

WHILE 1=1
BEGIN
WAITFOR TIME '01:00'
END

GO

Kristen
Go to Top of Page
   

- Advertisement -