假如我是2004-07-14上的班,那么我用这个如果实现我上了几天班?
select datediff(day,'2004-07-14','?')后面那个参数应该是7月最后一天,但是我怎么得到呢?
CASE语句里面的一部分:
then tb.atm_jyje/datediff(day,tb.actualdate,'?') else 0 end
...全文
988打赏收藏
关于时间间隔的问题,请教大家.
假如我是2004-07-14上的班,那么我用这个如果实现我上了几天班? select datediff(day,'2004-07-14','?')后面那个参数应该是7月最后一天,但是我怎么得到呢? CASE语句里面的一部分: then tb.atm_jyje/datediff(day,tb.actualdate,'?') else 0 end
set @tpdate=@stdate
while @tpdate<@eddate
begin
set @s3=@s3+cast(datediff(day,@tpdate,dateadd(month,1,@tpdate-day(@tpdate)+1)) as varchar(10))+','
set @tpdate=dateadd(month,1,@tpdate)
end
set @tpdate=@stdate
while @tpdate<@eddate
begin
set @s3=@s3+cast(datediff(day,@tpdate,dateadd(month,1,@tpdate-day(@tpdate)+1)-1) as varchar(10))+','
set @tpdate=dateadd(month,1,@tpdate)
end
select tb.atm_ztdesc,(select 项目=ratio_name from ratio where ratio_num=3),
sum(case when convert(varchar(7),tb.atm_jydate,120)='2004-06' then tb.atm_jyje/datediff(day,tb.atm_actualdate,'2004-06-30') else 0 end) as [2004-06]
from
(select a.atm_machnum,atm_jyje,atm_jydate,ratio_num,data_kind ,c.atm_ztdesc
from atm_jyinfo a,atm_baseinfo b,atm_ztinfo c
where a.atm_machnum=b.atm_machnum and b.atm_onsite=c.atm_ztnum
and a.atm_machnum in (select atm_machnum from contract_atminfo where contract_num='0001')
and a.atm_jydate>='2004-06-01' and a.atm_jydate<='2004-07-31' and ratio_num=3 and data_kind=1 ) tb group by tb.atm_ztdesc