views:

587

answers:

3

Is there a way to create a global variable in SQL Server so it's saved even the server is shut down, so I can use it in functions?

Example from what I need:

DECLARE @@DefaultValue bit

This variable should never be deleted unless I explicityl do so.

+2  A: 

Not a global variable.

There's chance you can define a global UDF like you can create a "system" stored proc (starts "sp" in master), but I've not tried it.

Note:

Even DECLARE @@DefaultValue bit is actually local:

@ means local variable, identifier is @DefaultValue

It's not really global: try SELECT @@DefaultValue from 2 another query window

gbn
+5  A: 

You can have a look at something like this

"Global variables" in SQL Server

astander
Ah OK, good idea.. :-)
gbn
+2  A: 

I guess this will work the best for me:

CREATE FUNCTION [dbo].[fn_GetDefaultPercent]()
RETURNS decimal(5,4)
AS
BEGIN
    RETURN 1.0000
END
Shimmy