Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


Click here to copy the following block
/*
(Date2 must be between Date1 and Date3, if Date3 is not null),
otherwise (Date2 can be null or Date2 must be >= Date1).
*/

set nocount on
drop table #d
go
-- One way to define the constraint
create table #d (date1 datetime, date2 datetime, date3 datetime,
check ((Date3 is null and (Date2 >= Date1 or Date2 is null)) or
           (Date3 is not null and Date2 between Date1 and Date3))
)
go
insert #d values('1/1/99', '1/2/99', '1/3/99')
insert #d values('1/1/99', null, null)
insert #d values('1/1/99', '1/3/99', null)
insert #d values('1/1/99', '1/3/98', null)

select * from #d
go

drop table #d
go
-- Another way to define the same constraint eliminating the different checks for NULL
create table #d (date1 datetime, date2 datetime, date3 datetime,
check (isnull(date2, '9999-12-31 23:59:59.998') between date1 and
   isnull(date3, '9999-12-31 23:59:59.998'))
)
go
insert #d values('1/1/99', '1/2/99', '1/3/99')
insert #d values('1/1/99', null, null)
insert #d values('1/1/99', '1/3/99', null)
insert #d values('1/1/99', '1/3/98', null)

select * from #d
go


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.