早教吧 育儿知识 作业答案 考试题库 百科 知识分享

SQL日期参数加具体钟点时间如何表示我想界定一个starttime>某一天某一个时间比如说starttime>2010/08/1117:30:00可以表示如果把日期换成参数该怎么表示starttime>@starttime17:30:00类似的?如何做是

题目详情
SQL 日期参数 加 具体钟点时间 如何表示
我想界定一个 starttime>某一天 某一个时间
比如说starttime>2010/08/11 17:30:00 可以表示
如果把日期换成参数该怎么表示
starttime>@starttime 17:30:00
类似的?如何做
是在sql server 2005环境中
说具体一些吧
select a.DNIS,count(*) as total from dbo.Call a where a.dnis=@dnis
and a.BeginTime between @starttime and @endtime
group by a.DNIS
这段文字 我想加个条件 就是begintime 大于 某一天的17:30
某一天用参数@starttime
下面3个答案我都尝试过,不太行.
▼优质解答
答案和解析
select a.DNIS,count(*) as total from dbo.Call a where a.dnis=@dnis
and a.BeginTime between @starttime and @endtime
and
(
a.BeginTime between
cast(
cast(year(a.BeginTime) as varchar(4))+'-'+
cast(month(a.BeginTime) as varchar(2))+'-'+
cast(day(a.BeginTime) as varchar(2))+' 17:30:00'
as datetime)
and
cast(
cast(year(a.BeginTime) as varchar(4))+'-'+
cast(month(a.BeginTime) as varchar(2))+'-'+
cast(day(a.BeginTime) as varchar(2))+' 22:30:00'
as datetime)
)
group by a.DNIS
-----------------------------------------
select a.DNIS,count(*) as total from dbo.Call a where a.dnis=@dnis
and a.BeginTime between @starttime and @endtime
and a.BeginTime > cast(
cast(year(@starttime) as varchar(4))
+'-'+cast(month(@starttime) as varchar(4))
+'-'+cast(day(@starttime) as varchar(4))
+' 17:30:00'
as datetime)
group by a.DNIS
-------------------------------------------------
select * from t1 where starttime > cast(
cast(year(@starttime) as varchar(4))
+'-'+cast(month(@starttime) as varchar(4))
+'-'+cast(day(@starttime) as varchar(4))
+' 17:30:00'
as datetime)