September 20, 2008 at 1:06 am
Hi All,
Is there any way to know the Max Capacity for a declared DataType programatically?
can we get the max Value for a SQLDataType using Select statement?
Thanks and Regards,
Rajesh
September 20, 2008 at 8:44 pm
Not that I know of... closest you might come is...
sp_Help BIGINT
... where BIGINT is the datatype.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 21, 2008 at 2:30 pm
You might want to read the description for SYS.SYSTEM_COLUMNS catalog view in Books On Line. It contains the max_length for columns expressed in bytes. It does not have values for VARCHAR(Max) or for XML columns, so in that regard is not complete. The value for a TEXT type column will be returned as 16, but you can use sp_tableoption 'test in row' to determine that capacity. In this regard it might be a little better than SYS.TYPES catalog view. But it might suffice for what you need. Also check the SYS.TYPES catalog view for the same information.
Sorry but this is the best I can do...
September 21, 2008 at 5:37 pm
Not 100% sure, but I don't believe that's what the OP is looking for. I believe they want to go someplace through T-SQL to figure out what the max for a given datatype is. For example, they want to go someplace to figure out the INT is capable of a binary 2 billion. Only way I can figure out to do that is to look in Books Online and make a table with the given mins and maxs for each datatype.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 21, 2008 at 6:44 pm
Can you get it from systypes?
select * from master.sys.systypes
I'm not quite sure if that's what you're meaning in your question.
Craig Outcalt
September 21, 2008 at 7:28 pm
That will certainly give you the number of bytes the datatype can or does occupy. But it will not give you the min or max values without prior knowledge of the datatype and writing code to produce that. And, in the case of datatypes like DATETIME, there is no way to establish the minimum value of 01/01/1753 based on just the number of bytes.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 21, 2008 at 10:39 pm
Thanks EveryBody,
So, I think we have to take the Max.Values manually for the Given DataType and then we can use it for other operations like comparing the value of the column whether it is within the maxValue of the DataType before inserting it into table.
Regards,
Rajesh
September 22, 2008 at 12:18 am
Jeff Moden (9/21/2008)
Only way I can figure out to do that is to look in Books Online and make a table with the given mins and maxs for each datatype.
This is what exactly what I wanted to suggest 🙂
Failing to plan is Planning to fail
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply