views:

311

answers:

2

Are there any constants in T-SQL like there are in some other languages that provide the max and min values ranges of data types such as int?

I have a code table where each row has an upper and lower range column, and I need an entry that represents a range where the upper range is the maximum value an int can hold(sort of like a hackish infinity). I would prefer not to hard code it and instead use something like SET UpperRange = int.Max

+1  A: 

I don't think there are any defined constants but you could define them yourself by storing the values in a table or by using a scalar valued function.

Table

Setup a table that has three columns: TypeName, Max and Min. That way you only have to populate them once.

Scalar Valued Function

Alternatively you could use scalar valued functions GetMaxInt() for example (see this StackOverflow answer for a real example.

You can find all the max/min values here: http://msdn.microsoft.com/en-us/library/ms187752.aspx

vfilby
+1  A: 

No, not natively. There are two options:

  • user-defined scalar function
  • properties table

In Oracle, you can do it within Packages - the closest SQL Server has is Assemblies...

OMG Ponies