Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-08-25 : 10:23:13
|
| Umair writes "I need help with inserting maximum value of datetime datatype in a column as default.I have a table with column Enddate defined with datetime datatype. I want to insert the maximum value of datetime datatype as default when no value is provided for that column. I cant seem to figure out how to determine the maximum value of datetime datatype programmatically or by tsql rather than hard coding it in the insert command.Thanks" |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-08-25 : 11:18:15
|
| What is wrong with hard coding it, since there is only one possible maximum datetime value, and it doesn't change?CODO ERGO SUM |
 |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-08-25 : 11:22:02
|
| Just set the default value for the column to 12/31/9999, which is the maximum date you can put in a datetime. You don't have to code it in the INSERT, create it as a default in the table definition. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-08-26 : 00:40:26
|
| Why dont you use NULL to specify there is no value?MadhivananFailing to plan is Planning to fail |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2006-08-26 : 01:20:35
|
| [code]create function dbo.MaxDate()RETURNS datetimeasbeginreturn '99991231 23:59:59.997'endgoselect dbo.MaxDate()[/code]DavidMProduction is just another testing cycle |
 |
|
|
|
|
|