22,207
社区成员
发帖
与我相关
我的任务
分享
select sum(po_cost)as cost,month(order_date)as month
from purview
where year(order_date)='2008'
group by month(order_date)
alter function ToRealMM(@TheDateTime datetime) returns integer
as
begin
if @TheDateTime<='2008-09-25'
return(month(@TheDateTime))
if(day(@TheDateTime)<=25)
return(month(@TheDateTime))
if(month(@TheDateTime)=12)
return(1)
return(month(@TheDateTime)+1)
end
select dbo.ToRealMM('2007-12-26')
-----------
13
(1 行受影响)
select dbo.ToRealMM('2008-12-26')
-----------
13
(1 行受影响)
select sum(po_cost)as cost,
case when month(order_date) <9 then month(order_date)
else
case when day(order_date)<=25 then month(order_date)
else
month(order_date)+1
end
end as month
from purview
where order_date>='2008-1-1' and order_date<'2008-12-26'
group by
case when month(order_date) <9 then month(order_date)
else
case when day(order_date)<=25 then month(order_date)
else month(order_date)+1
end
end
select sum(po_cost)as cost,case when month(order_date) <9 then month(order_date)
else
case when day(order_date)<=25 then month(order_date)
else month(order_date)+1
end
end as month
from purview
where order_date>='2008-1-1'
and order_date<'2008-12-26'
group by case when month(order_date) <9 then month(order_date)
else
case when day(order_date)<=25 then month(order_date)
else month(order_date)+1
end
end
select sum(po_cost*cur_rate)as dd,dbo.ToRealMM(order_date) as mm
from purview left join arap_currency on curr_code=cur_code
where year(order_date)=@year
group by dbo.ToRealMM(order_date)
--ToRealMM函数
CREATE function ToRealMM(@TheDateTime datetime) returns integer
as
begin
if year(@TheDateTime)<=2008 and month(@TheDateTime)<9
return(month(@TheDateTime))
if year(@TheDateTime)=2008 and month(@TheDateTime)=9 and day(@TheDateTime) between 1 and 25
return(month(@TheDateTime))
if(day(@TheDateTime)<=25)
return(month(@TheDateTime))
return(month(@TheDateTime)+1)
end