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 |
|
onkabetse
Starting Member
5 Posts |
Posted - 2011-04-26 : 10:01:38
|
| How can I validate a column to accept the current date as the default date? I have already validated the same column (orderdate) to accept date less than the current date and has worked well using (([orderdate] < GETDATE ()))If the orderdate is not entered, the current date should be taken as the default date. |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-04-26 : 10:05:07
|
| A few waysyou can create a defaultcreate table a(dte datetime default getdate())now if you insert into the table and don't specify a date it will use getdate().You could use a trigger to set the date on an insertYou could use getdate() in the insert statement==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-04-26 : 11:03:48
|
| In addition to doing what Nigel suggested, you may want to make one other change, rra. That change is to amend the CHECK constraint to (([orderdate] <= GETDATE ())). Without that, the default value (which is getdate()) will violate the CHECK constraint. |
 |
|
|
|
|
|