![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Does anyone know of a built-in function to return the maximum possible value of a given datatype? I have to return the biggest value for a smalldatetime or datetime in a view if the field is null, but can't find such a function. The closest I've come is: select datalength(cast(getdate() as smalldatetime)) ...but that only return the number of bytes, not the value itself, which is '6-6-2079 11:59' I know I could create my own lookup table and function, but I was hoping that Transact-SQL would have a built-in solution --John Hunter |
#3
| |||
| |||
|
|
How about just hardcoding what is in the documentation? DATETIME, for example says "Date and time data from January 1, 1753 through December 31, 9999, to an accuracy of one three-hundredth of a second (equivalent to 3.33 milliseconds or 0.00333 seconds)." Which after consulting the accompanying chart comes to 9999-12-31 23:59:59.997. Roy Harvey Beacon Falls, CT |
#4
| |||
| |||
|
|
On Jun 27, 1:56 pm, Roy Harvey <roy_har... (AT) snet (DOT) net> wrote: How about just hardcoding what is in the documentation? DATETIME, for example says "Date and time data from January 1, 1753 through December 31, 9999, to an accuracy of one three-hundredth of a second (equivalent to 3.33 milliseconds or 0.00333 seconds)." Which after consulting the accompanying chart comes to 9999-12-31 23:59:59.997. Roy Harvey Beacon Falls, CT I've had to do just that, but it would be nice if I could have the view do the job via a function. For example, if the underlying table changed from a smalldatetime to a datetime, then all views which use it would automatically return the correct maximum value --John Hunter |
#5
| |||
| |||
|
|
One alternative is to write your own function that encapsulates the hardcode. Pass the table and column names, query the system tables for the type and related information such as max length of a varchar, and then return it. Clumsy, no doubt. |
#6
| |||
| |||
|
|
Does anyone know of a built-in function to return the maximum possible value of a given datatype? I have to return the biggest value for a smalldatetime or datetime in a view if the field is null, |
#7
| |||
| |||
|
|
Does anyone know of a built-in function to return the maximum possible value of a given datatype? I have to return the biggest value for a smalldatetime or datetime in a view if the field is null, but can't find such a function. The closest I've come is: select datalength(cast(getdate() as smalldatetime)) ...but that only return the number of bytes, not the value itself, which is '6-6-2079 11:59' I know I could create my own lookup table and function, but I was hoping that Transact-SQL would have a built-in solution --John Hunter |
![]() |
| Thread Tools | |
| Display Modes | |
| |