日期:2014-05-18  浏览次数:20490 次

很简单的问题,求时候段的!非常急!
from_date                                     end_date
-----------------------       -------------------
2007-05-01   00:00:00 2007-06-06   00:00:00
2007-10-01   00:00:00 2007-10-10   00:00:00
表的结构如上,
现在我想写一存储过程,两个参数,一个开始时间,一个结束时间,也就是我想用这个存储过程判断一个时间段是否在这个表里的时间段内,如果在返回1,如果不在返回0,谢谢大家了,

------解决方案--------------------
declare @Date datetime
set @Date = getdate()
if exists (select 1 from TAB where from_date = < @Date and end_date > = @Date)
return(1)
else
return(0)
------解决方案--------------------

create proc p_test(@dt1 datetime, @dt2 datetime)
as


if exists (select 1 from 表名 where (@dt1 between 开始日期 and 结束日期) and (@dt2 between 开始日期 and 结束日期))
select 1
else
select 0
go

------解决方案--------------------
create proc test
@Sdate smalldatetime,
@Edate smalldatetime
as
if exists(select 1 from [Table] where datediff(day,from_date,@Sdate)> =0 and datediff(day,@Edate,end_date)> =0)
return 1
else
return 0
------解决方案--------------------
create proc p_test(@dt1 datetime, @dt2 datetime,@result int out) as
begin
declare @_date datetime
declare @a int --返回的值
_date= '2007-10-10 00:00:00 '--你所要判断的时间值
if _date> =@dt1 and _date <=@dt2
@a=1
else
@a=0
return @a
end
------解决方案--------------------
declare @Date1 datetime,@Date2 datetime,@Tmp datetime

set @Date1 = ...
set @Date2 = ...

if @Date1 > @Date2 select @Tmp = @Date1, @Date1 = @Date2, @Date2 = @Tmp

if exists (select 1 from TAB where from_date = < @Date1 and end_date > = @Date2)
return(1)
else
return(0)
------解决方案--------------------
--这不是两个参数?

create proc p_test(@dt1 datetime, @dt2 datetime)
as


if exists (select 1 from 表名 where (@dt1 between 开始日期 and 结束日期) and (@dt2 between 开始日期 and 结束日期))
select 1
else
select 0
go