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
 General SQL Server Forums
 New to SQL Server Programming
 Global Variable

Author  Topic 

Beginer2012
Starting Member

45 Posts

Posted - 2012-05-03 : 14:54:33
Hi,
Is it possible to create a global variable and modify its content ?
If not what is the alternative for global variables in SQL Sever ?

Thank you

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-03 : 15:01:42
why do you need a global variable? Till what point you want to use value thats held in variable? you want share the value across connections? Perhaps you can explain exact scenario

Users cant create global variables in sql server neither can they update their values directly using selects. Though they're referred as global variables, they're actually system functions like @@error,@@trancount etc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Beginer2012
Starting Member

45 Posts

Posted - 2012-05-03 : 21:40:48
Hello,
I have around 50 procedures they use almost the same set of fixed numbers to perform some calculations. So I want procedure1 to procedure50 to be able to access the same variables without having to declare them in every procedure or without calling a function that returns these values.
Thank you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-03 : 21:44:34
quote:
Originally posted by Beginer2012

Hello,
I have around 50 procedures they use almost the same set of fixed numbers to perform some calculations. So I want procedure1 to procedure50 to be able to access the same variables without having to declare them in every procedure or without calling a function that returns these values.
Thank you


why not store values in a table and use it inside procs?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Beginer2012
Starting Member

45 Posts

Posted - 2012-05-03 : 23:33:03
Then I have to perform a select each time I call a proc to assign the value to a var which add up to 50 selects.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-04 : 18:34:41
quote:
Originally posted by Beginer2012

Then I have to perform a select each time I call a proc to assign the value to a var which add up to 50 selects.



even from variable you've retrieve the values right?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Beginer2012
Starting Member

45 Posts

Posted - 2012-05-04 : 19:09:07
Yes..I have to retrieve the value from a variable but it is less code.
Go to Top of Page
   

- Advertisement -