日期:2014-05-17 浏览次数:20657 次
--racer
if object_id('racer','u') is not null
drop table racer
create table racer
(
id int primary key,
name nvarchar(20),
team nvarchar(20),
begindate date,
enddate date
)
go
insert into racer values
(1001,'name1','team1','2012-02-12','2012-07-09'),
(1002,'name2','team2','2012-03-12','2012-08-09'),
(1003,'name3','team3','2012-04-12','2012-09-09'),
(1004,'name4','team4','2012-05-12','2012-10-09'),
(1005,'name5','team5','2012-06-12','2012-11-09'),
(1006,'name6','team6','2012-07-12','2012-12-09')
go
--SQL
declare @date1 date
declare @date2 date
set @date1='2012-04-23'
set @date2='2012-11-23'
select *From racer
where begindate<@date2 or enddate>@date1
--结果集
--1001 name1 team1 2012-02-12 2012-07-09
--1002 name2 team2 2012-03-12 2012-08-09
--1003 name3 team3 2012-04-12 2012-09-09
--1004 name4 team4 2012-05-12 2012-10-09
--1005 name5 team5 2012-06-12 2012-11-09
--1006 name6 team6 2012-07-12 2012-12-09