Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
i am trying to create a table that has a date in it i need to check that the date is greater then or equal the currnet date how do i do this James
cshah1
Constraint Violating Yak Guru
347 Posts
Posted - 2005-03-04 : 10:57:23
DATEDIFFReturns the number of date and time boundaries crossed between two specified dates. SyntaxDATEDIFF ( datepart , startdate , enddate )
rockmoose
SQL Natt Alfen
3279 Posts
Posted - 2005-03-04 : 10:59:00
I presume old data can have dates older than current date.
-- on new tablecreate table #t(d datetime check( d>=getdate()))-- on existing tablealter table t with nocheck add constraint chkDate check(d>=getdate())drop table t
rockmoose
X002548
Not Just a Number
15586 Posts
Posted - 2005-03-04 : 11:04:18
EDIT: DoohBut you probably want to incorporate datediff to eliminate the tome factor.
USE NorthwindGOSET NOCOUNT ONCREATE TABLE myTable99(Col1 int IDENTITY(1,1) , myDate datetime CHECK(DATEDIFF(dd,GetDate(),myDate)>=0))GOINSERT INTO myTable99(myDate) SELECT '1/1/9999'GOSELECT * FROM myTable99GOINSERT INTO myTable99(myDate) SELECT '1/1/1900'GOSET NOCOUNT OFFDROP TABLE myTable99GO