Hello everyone, I want to create a global constants that I can call in stored procedure in SQL server. How can that be done? The reason is that I have to change the value of that constant regularly and I don't want to go to each stored procedure, which is
a lot of work.
Hello jgangwisch, thanks for the suggestion. My problem is I have quite many constants that I need to create (around 20 constants). What I did in visual studio is to create a class and declare it as public. Something like:
Public Const test As String="12345"
Is there a way to do something similar in SQL server? how about Global variable? Can it be used?
Yes perhaps table is the way to go. I have seen some TSQL calling @@Error and other @@ without declaring them. I thought maybe there is a way that I could some variables in a similar way.
asplearning
Participant
909 Points
953 Posts
Creating public constants in SQL server possible?
Jun 25, 2012 12:12 AM|LINK
Hello everyone, I want to create a global constants that I can call in stored procedure in SQL server. How can that be done? The reason is that I have to change the value of that constant regularly and I don't want to go to each stored procedure, which is a lot of work.
Is there a way I can have a global constant?
Thanks.
jgangwisch
Contributor
2449 Points
366 Posts
Re: Creating public constants in SQL server possible?
Jun 25, 2012 12:58 AM|LINK
This can be achieved. What you will do is create a function with the value. For example:
Thanks,
Jason
asplearning
Participant
909 Points
953 Posts
Re: Creating public constants in SQL server possible?
Jun 25, 2012 01:11 AM|LINK
Hello jgangwisch, thanks for the suggestion. My problem is I have quite many constants that I need to create (around 20 constants). What I did in visual studio is to create a class and declare it as public. Something like:
Is there a way to do something similar in SQL server? how about Global variable? Can it be used?
alvingeorge
Participant
925 Points
203 Posts
Re: Creating public constants in SQL server possible?
Jun 25, 2012 01:38 AM|LINK
Please take a look at the post here http://weblogs.sqlteam.com/mladenp/archive/2007/04/23/60185.aspx.
There is no global variable concept in SQL server. You can create one table and write common sp to retrive that.
asplearning
Participant
909 Points
953 Posts
Re: Creating public constants in SQL server possible?
Jun 25, 2012 01:43 AM|LINK
Yes perhaps table is the way to go. I have seen some TSQL calling @@Error and other @@ without declaring them. I thought maybe there is a way that I could some variables in a similar way.
Thanks.
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: Creating public constants in SQL server possible?
Jun 25, 2012 02:12 AM|LINK
Create a table with one row and a column for each variable you want to store.
asplearning
Participant
909 Points
953 Posts
Re: Creating public constants in SQL server possible?
Jun 26, 2012 04:25 AM|LINK
Now I will just create a table as suggested. Thanks for all the replies.