Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 26, 2012 04:25 AM by asplearning
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?
Jun 25, 2012 12:58 AM|LINK
This can be achieved. What you will do is create a function with the value. For example:
create function fnGetPi()
--this will retrieve the value
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:
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?
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.
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.
Jun 25, 2012 02:12 AM|LINK
Create a table with one row and a column for each variable you want to store.
Jun 26, 2012 04:25 AM|LINK
Now I will just create a table as suggested. Thanks for all the replies.