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 |
fusion86
Starting Member
4 Posts |
Posted - 2013-10-05 : 09:25:12
|
Hi allAppreciate your help all.. I am trying to put in a check to ensure that the YearEnrolled - DateOfBirth is at least 16 years. Please advise me on the correct code.CREATE TABLE Student( [DateOfBirth] [date] NOT NULL, [YearEnrolled] [date] NOT NULL, SELECT DATEPART(yyyy,DateofBirth) AS BirthYear, CONSTRAINT DateOfBirth_CHECK CHECK(YearEnrolled-BirthYear =<16),); |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2013-10-06 : 03:02:46
|
[code]CREATE TABLE Student( [DateOfBirth] [date] NOT NULL, [YearEnrolled] [date] NOT NULL, BirthYear as DATEPART(YEAR, [DateOfBirth]), CONSTRAINT DateOfBirth_CHECK CHECK (DATEDIFF(YEAR, [DateOfBirth], [YearEnrolled]) >= 16));[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
fusion86
Starting Member
4 Posts |
Posted - 2013-10-09 : 02:10:46
|
Thanks alot for your help!! |
|
|
|
|
|