SELECT 總科代碼,
本月數=sum(case when year(日期)=year(:ldt) and month(日期) = month(:ldt) then isnull(匯率,0) * isnull(金額,0) else 0 end),
本年累計數=sum(case when year(日期)=year(:ldt) and month(日期) <= month then isnull(匯率,0) * isnull(金額,0) else 0 end)
FROM V_財務_銀行_現金_記帳_流水帳2
group by 總科代碼
本月數=sum(case when year(日期)=year(:ldt) and month(日期) = month(:ldt) then isnull(匯率,0) * isnull(金額,0) else 0 end),
本年累計數=sum(case when year(日期)=year(:ldt) and month(日期) <= month then isnull(匯率,0) * isnull(金額,0) else 0 end)
FROM V_財務_銀行_現金_記帳_流水帳2
group by 總科代碼
本月數=sum(case when datediff(month,日期,getdate())=0 then isnull(匯率,0) * isnull(金額,0) else 0 end),
本年累計數=sum(case when datediff(year,日期,getdate())=0 then isnull(匯率,0) * isnull(金額,0) else 0 end)
FROM V_財務_銀行_現金_記帳_流水帳2
group by 總科代碼
select isnull(sum(isnull(匯率,0) * isnull(金額,0)),0)
from V_財務_銀行_現金_記帳_流水帳2
where year(日期)=year(:ldt) and month(日期) <= month(:ldt)
where 總科代碼=V.總科代碼 ) from FROM V_財務_銀行_現金_記帳_流水帳2 Vgroup by 總科代碼
sum(case when year(日期)=year(:ldt) and month(日期) = month(:ldt) then isnull(匯率,0) * isnull(金額,0) else 0 end) [本月數],
sum(case when year(日期)=year(:ldt) and month(日期) = month(:ldt) then isnull(匯率,0) * isnull(金額,0) else 0 end) [ 本年累計數]
FROM V_財務_銀行_現金_記帳_流水帳2
group by 總科代碼