Thursday, 9 August 2012
#23 Penggunaan Case pada kondisi


select a.budgetid, budget, b.totalcost, amount,
case when c.budgetid is null then b.totalcost else b.totalcost+amount end x
from vbudgetcapex a
inner join (
select budgetid, SUM(totalcost) totalcost from trcapexdetail a
inner join TrCapexHeader b on (a.capexid=b.capexid)
where a.capexid=85
group by budgetid
) b on (a.budgetid=b.budgetid)
left join [vcapex_pemakaianbudget] c on (a.budgetid=c.budgetid)
where budget < (case when c.budgetid is null then b.totalcost else b.totalcost+amount end)
case when c.budgetid is null then b.totalcost else b.totalcost+amount end x
from vbudgetcapex a
inner join (
select budgetid, SUM(totalcost) totalcost from trcapexdetail a
inner join TrCapexHeader b on (a.capexid=b.capexid)
where a.capexid=85
group by budgetid
) b on (a.budgetid=b.budgetid)
left join [vcapex_pemakaianbudget] c on (a.budgetid=c.budgetid)
where budget < (case when c.budgetid is null then b.totalcost else b.totalcost+amount end)
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment