• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7318
  • Last Modified:

How to Declare a global variable in SQL Server

How can I declare a global variable in SQL Server?
I want this varaiable to be visible across multiple stored procedures.
0
marti
Asked:
marti
  • 2
  • 2
  • 2
1 Solution
 
BrianWrenCommented:
null
0
 
BrianWrenCommented:
(oops... sorry, didn't mean to post.)
0
 
Gustavo Perez BuenrostroCommented:
You can not declare global variables in SQL Server. However, you can create a global temporary table to store all values you need to share. Let me know if you need more detail about this.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
martiAuthor Commented:
gpbuenrostro, could you please refer to a source which would clarify this article?
0
 
Gustavo Perez BuenrostroCommented:
“Global variables are predefined and maintained by the system”.

The only way to resolve this problem is creating a table in which you must store the values of all your “global” variables and use a stored procedure to get the values from this table whenever you need them.

To get more detail see:

-"variables" definition on Glossary of BOL.
-Question 10198058 on EE:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=mssql&qid=10198058 
0
 
martiAuthor Commented:
Thank you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now