Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

T-SQL global variables

Status
Not open for further replies.

MikeDNova

Programmer
Jul 3, 2002
86
US
Is it possible to use global variables in T-SQL? and how? if not, what's the common way to get around this problem?

Thanks in advance!
Mike
 
Global in what regards? Global across Stored Procs? Global across connections?

I would think that where you have a need for such globals, that you store them as meta-data in your database. Just create a new table, called "GLOBAL_VARIABLES" or somesuch, give them a name and a data type, value, etc, and nice SPs for getting, setting, locking...etc.

Regards,
TR
 
Yeah something like that might work. But what I'm trying to do is call a function, set the global variable, then call then function again and remember the global. Maybe there's no easy way to do this in T-SQL.
 
Variables within functions that retain their value across invocation are known as "static" variables.

T-SQL doesn't have anything like that, at least not that I am aware of.

TR
 
Create a Global Variable Table and insert the values for your variable there.

 
Great idea mcarrillo...where did I hear that before?

;-)

tr
 
:) TJRTech Just agreeing with your creative solution.

mcarrill aka martyc71
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top