Sunday, December 14, 2014

Day Wise Account Balance Statement (Generat Manual Data Full Month).

CREATE TABLE AC_BAL
(
  AC_NUMBER  NUMBER,
  BALANCE    NUMBER,
  TR_DATE    DATE
);

SET DEFINE OFF;
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (1, 3000, TO_DATE('12/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (1, 2000, TO_DATE('12/04/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (1, 8000, TO_DATE('12/16/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (1, 5000, TO_DATE('12/29/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (2, 5000, TO_DATE('12/29/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into AC_BAL
   (AC_NUMBER, BALANCE, TR_DATE)
 Values
   (3, 200, TO_DATE('12/16/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;
------ Query For Generate Statement ---------------

SELECT B.AC_NUMBER, NVL(BALANCE,0) BALANCE, DAYS
FROM AC_BAL A RIGHT OUTER JOIN (SELECT DISTINCT AC_NUMBER,DAYS FROM AC_BAL, (
SELECT (CASE WHEN LEVEL>1 THEN TRUNC(TO_DATE('30-DEC-2014'),'MM')+(LEVEL-1) ELSE TRUNC(TO_DATE('30-DEC-2014'),'MM')  END) DAYS
FROM   DUAL
CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY('30-DEC-2014'),'DD')))
ORDER BY AC_NUMBER) B
ON (A.TR_DATE=B.DAYS AND B.AC_NUMBER=A.AC_NUMBER)
ORDER BY B.AC_NUMBER, DAYS

No comments:

Post a Comment