上的提问是:有两个日期字段 StartDate EndDate
2008-03-01 08:30:00 2008-12- 12 19:30:30
意思是自2008-03-01 08:30:00 至 2008-12- 12 19:30:30 每天8:30-19:30 之间合法 怎么判断2008 06 21 18:30 是不是合法? 答案:
SQL code
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([StartDate] datetime,[EndDate] datetime)
insert [tb]
select '2008-03-01 08:30:00','2008-12-12 19:30:30'declare @date datetime
set @date='2008-06-21 18:30'
if exists(select *
from tb
where @date between startdate and enddate
and convert(char(8),@date,108) between convert(char(8),StartDate,108) and convert(char(8),EndDate,108))
print '合法'
else
print '不合法'正常的问题已经解决,但是如果StartDate EndDate
2008-03-01 19:30:00 2008-12- 12 8:30:30
意思是自2008-03-01 至 2008-12- 12 每天19:30-8:30 之间合法 怎么判断2008 06 21 18:30 是不是合法?
上面的SQL就不灵了 这咋个办?
2008-03-01 08:30:00 2008-12- 12 19:30:30
意思是自2008-03-01 08:30:00 至 2008-12- 12 19:30:30 每天8:30-19:30 之间合法 怎么判断2008 06 21 18:30 是不是合法? 答案:
SQL code
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([StartDate] datetime,[EndDate] datetime)
insert [tb]
select '2008-03-01 08:30:00','2008-12-12 19:30:30'declare @date datetime
set @date='2008-06-21 18:30'
if exists(select *
from tb
where @date between startdate and enddate
and convert(char(8),@date,108) between convert(char(8),StartDate,108) and convert(char(8),EndDate,108))
print '合法'
else
print '不合法'正常的问题已经解决,但是如果StartDate EndDate
2008-03-01 19:30:00 2008-12- 12 8:30:30
意思是自2008-03-01 至 2008-12- 12 每天19:30-8:30 之间合法 怎么判断2008 06 21 18:30 是不是合法?
上面的SQL就不灵了 这咋个办?
insert [tb]
select '2008-03-01 08:30:00','2008-12-12 19:30:30' declare @date datetime
set @date='2008-06-21 18:30'
if exists(select * from tb where @date between startdate and enddate)
print '合法'
else
print '不合法'
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([StartDate] datetime,[EndDate] datetime)
insert [tb]
select '2008-03-01 08:30:00','2008-12-12 19:30:30' declare @date datetime
set @date='2008-06-21 18:30'
if exists(select *
from tb
where @date between startdate and enddate
and (convert(char(8),@date,108) between convert(char(8),StartDate,108) and convert(char(8),EndDate,108)) or convert(char(8),@date,108) between convert(char(8),EndDate,108) and convert(char(8),StartDate,108)))
print '合法'
else
print '不合法'
2008-03-01 19:30:00 2008-12- 12 8:30:30
意思是自2008-03-01 至 2008-12- 12 每天19:30-8:30 之间合法 怎么判断2008 06 21 18:30 是不是合法?
上面的SQL就不灵了 这咋个办?