Hello,
Is there a way to get the last value in a column into the next row
My table looks like this
Day Begin Invoice Cash Change Ending
1 7500 2500 500 2000 [highlight #FCE94F]7000[/highlight]
2 [highlight #FCE94F]7000[/highlight] 1500 1000 500 [highlight #FCE94F]6500[/highlight]
3 [highlight #FCE94F]6500[/highlight] 4500 2500 2000 4500
I tried the example below, but that didn't work, it just gives me the first day
The CALCURMO table is the current month by days. day = dy
The ARBBALANCE has the very first record (Balance) of the Begin column
The ARDAILYBI1 table has the INVAM01 = INVOICE and AMTRC01 = CASH
THE CHANGE is a calculation
Is there a way to get the last value in a column into the next row
My table looks like this
Day Begin Invoice Cash Change Ending
1 7500 2500 500 2000 [highlight #FCE94F]7000[/highlight]
2 [highlight #FCE94F]7000[/highlight] 1500 1000 500 [highlight #FCE94F]6500[/highlight]
3 [highlight #FCE94F]6500[/highlight] 4500 2500 2000 4500
I tried the example below, but that didn't work, it just gives me the first day
Code:
SELECT
CASE WHEN DAY ='SATURDAY' THEN 1 WHEN DAY = 'SUNDAY' THEN 1 ELSE 0 END AS DYWK,
CALCURMO."DAY",
CALCURMO.DY,
ARBBALANCE.BALANCE,
(CASE WHEN CALCURMO.DY < 02 THEN ARBBALANCE.BALANCE WHEN CALCURMO.DY > 01 then (CASE WHEN ARBBALANCE.BALANCE - (ARDAILYBI1.INVAM01 - ARDAILYBI1.AMTRC01) < 0 THEN ARBBALANCE.BALANCE - (ARDAILYBI1.INVAM01 - ARDAILYBI1.AMTRC01) *-1 ELSE ARBBALANCE.BALANCE - (ARDAILYBI1.INVAM01 - ARDAILYBI1.AMTRC01) END) END)AS BGBAL,
ARDAILYBI1.INVAM01,
ARDAILYBI1.AMTRC01,
CASE WHEN (ARDAILYBI1.INVAM01 - ARDAILYBI1.AMTRC01) < 0 THEN (ARDAILYBI1.INVAM01 - ARDAILYBI1.AMTRC01) * -1 ELSE (ARDAILYBI1.INVAM01 - ARDAILYBI1.AMTRC01) END AS CHANGE1,
CASE WHEN ARBBALANCE.BALANCE - (ARDAILYBI1.INVAM01 - ARDAILYBI1.AMTRC01) < 0 THEN ARBBALANCE.BALANCE - (ARDAILYBI1.INVAM01 - ARDAILYBI1.AMTRC01) *-1 ELSE ARBBALANCE.BALANCE - (ARDAILYBI1.INVAM01 - ARDAILYBI1.AMTRC01) END AS ENDINGBALANCE
FROM CALCURMO
LEFT OUTER JOIN ARBBALANCE ON CALCURMO.DY = ARBBALANCE.DY
LEFT OUTER JOIN ARDAILYBI1 ON CALCURMO.DY = ARDAILYBI1.DYTRNDT
WHERE (CASE WHEN DAY ='SATURDAY' THEN 1 WHEN DAY = 'SUNDAY' THEN 1 ELSE 0 END <>1)
The CALCURMO table is the current month by days. day = dy
The ARBBALANCE has the very first record (Balance) of the Begin column
The ARDAILYBI1 table has the INVAM01 = INVOICE and AMTRC01 = CASH
THE CHANGE is a calculation