SELECT *
  FROM SIEBEL.S_LOY_MEMBER
 WHERE MEM_NUM = '5188455';

SELECT *
  FROM SIEBEL.S_LOY_TXN
 WHERE MEMBER_ID = '1-71H-2070' AND ROW_ID = '1-99L10OL';

SELECT *
  FROM SIEBEL_PURGE.TEMP_TXN_10212015
 WHERE ROW_ID = '1-99KQDEF';

  SELECT TXN_ID, SUM (ACCRUALED_VALUE)
    FROM SIEBEL.S_LOY_ACRL_ITM A
         INNER JOIN SIEBEL_PURGE.TEMP_TXN_10212015 T ON T.ROW_ID = A.TXN_ID
   WHERE TXN_ID = '1-99L10OL'
GROUP BY TXN_ID;

SELECT COUNT (*)
  FROM SIEBEL_PURGE.TEMP_TXN_10212015
 WHERE TOTAL_POINTS IS NOT NULL;

  SELECT *
    FROM SIEBEL_PURGE.TEMP_TXN_10212015
   WHERE     PROCESS_DT IS NOT NULL
         AND (NUM_POINTS <> TOTAL_POINTS OR TOTAL_POINTS IS NULL)
ORDER BY PROCESS_DT DESC;

SELECT M.MEM_NUM, TT.ROW_ID
  FROM SIEBEL.S_LOY_TXN T
       INNER JOIN SIEBEL_PURGE.TEMP_TXN_10212015 TT
          ON     TT.ROW_ID = T.ROW_ID
             AND TT.PROCESS_DT IS NOT NULL
             AND (TT.NUM_POINTS <> TT.TOTAL_POINTS OR TT.TOTAL_POINTS IS NULL)
       INNER JOIN SIEBEL.S_LOY_MEMBER M ON T.MEMBER_ID = T.MEMBER_ID;

  SELECT TT.*, M.MEM_NUM
    FROM SIEBEL.S_LOY_TXN T
         INNER JOIN SIEBEL.S_LOY_MEMBER M ON M.ROW_ID = T.MEMBER_ID
         INNER JOIN SIEBEL_PURGE.TEMP_TXN_10212015 TT ON T.ROW_ID = TT.ROW_ID
   WHERE T.ROW_ID IN ('1-RFD-9844', '1-99VURJU')
ORDER BY TT.PROCESS_DT DESC;

SELECT *
  FROM SIEBEL.S_LOY_TXN
 WHERE ROW_ID = '1-99K3P1N';

SELECT ACCRUAL_ITEM_ID
  FROM SIEBEL.S_LOY_RDM_ITM R
       INNER JOIN SIEBEL.S_LOY_ACRL_ITM$A A ON A.ROW_ID = R.ACCRUAL_ITEM_ID
 WHERE R.TXN_ID = '1-99K3P1N';

SELECT ACCRUAL_ITEM_ID
  FROM SIEBEL.S_LOY_RDM_ITM R
       INNER JOIN SIEBEL_PURGE.P_INT_S_LOY_RDM_ITM_10012012 A
          ON A.RDM_ID = R.ACCRUAL_ITEM_ID
 WHERE R.TXN_ID = '1-99K3P1N';

  SELECT R.TXN_ID, COUNT (*)
    FROM SIEBEL.S_LOY_RDM_ITM R
         INNER JOIN SIEBEL.S_LOY_ACRL_ITM$A A
            ON     A.ROW_ID = R.ACCRUAL_ITEM_ID
               AND R.CREATED BETWEEN (SYSDATE - 7) AND (SYSDATE - 2)
GROUP BY R.TXN_ID;

SELECT DISTINCT MEMBER_ID, M.MEM_NUM
  FROM SIEBEL.S_LOY_TXN T
       INNER JOIN
       (  SELECT R.TXN_ID, COUNT (*)
            FROM SIEBEL.S_LOY_RDM_ITM R
                 INNER JOIN SIEBEL.S_LOY_ACRL_ITM$A A
                    ON     A.ROW_ID = R.ACCRUAL_ITEM_ID
                       AND R.CREATED BETWEEN (SYSDATE - 7) AND (SYSDATE - 2)
        GROUP BY R.TXN_ID) R
          ON R.TXN_ID = T.ROW_ID
       INNER JOIN SIEBEL.S_LOY_MEMBER M ON M.ROW_ID = T.MEMBER_ID;

SELECT SYSDATE - 2
  FROM DUAL;

INSERT INTO SIEBEL_PURGE.P_INT_S_LOY_RDM_ITM_10012012 (MEM_ID,
                                                       RDM_ID,
                                                       PRV_ACRL_ID,
                                                       TASK_NUM)
   SELECT R.MEMBER_ID,
          R.ROW_ID,
          R.ACCRUAL_ITEM_ID,
          1
     FROM SIEBEL.S_LOY_RDM_ITM R
          INNER JOIN SIEBEL.S_LOY_ACRL_ITM$A A
             ON     A.ROW_ID = R.ACCRUAL_ITEM_ID
                AND R.CREATED BETWEEN (SYSDATE - 7) AND (SYSDATE - 2);

SELECT R.MEMBER_ID,
       R.ROW_ID,
       R.ACCRUAL_ITEM_ID,
       1
  FROM SIEBEL.S_LOY_RDM_ITM R
       INNER JOIN SIEBEL.S_LOY_ACRL_ITM$A A
          ON     A.ROW_ID = R.ACCRUAL_ITEM_ID
             AND R.CREATED BETWEEN TO_DATE ('10/14/2015', 'mm/dd/yyyy')
                               AND TO_DATE ('10/18/2015', 'mm/dd/yyyy');

  SELECT *
    FROM SIEBEL_PURGE.TEMP_TXN_10212015
   WHERE     PROCESS_DT BETWEEN TO_DATE ('10/18/2015', 'mm/dd/yyyy')
                            AND SYSDATE
         AND PROCESS_DT IS NOT NULL
         AND (NUM_POINTS <> TOTAL_POINTS)
         AND PROMO_POINTS > 0
ORDER BY PROCESS_DT DESC;

  SELECT *
    FROM SIEBEL.S_LOY_ACRL_ITM
   WHERE MEMBER_ID = '1-839-4257' AND ATTRIB_DEFN_ID = '1-162W'
ORDER BY PROCESS_DT DESC;

  SELECT *
    FROM SIEBEL.S_LOY_ACRL_ITM
   WHERE TXN_ID IN ('1-UDNC-405', '1-99Z5P92', '1-99Z5P7A')
ORDER BY PROCESS_DT DESC;

SELECT *
  FROM SIEBEL.S_LOY_ACRL_ITM
 WHERE     TXN_ID IN
              (SELECT ROW_ID
                 FROM SIEBEL_PURGE.TEMP_TXN_10212015
                WHERE     PROCESS_DT BETWEEN TO_DATE ('10/18/2015',
                                                      'mm/dd/yyyy')
                                         AND SYSDATE
                      AND PROCESS_DT IS NOT NULL
                      AND (NUM_POINTS <> TOTAL_POINTS))
       AND PRTNR_PT_DEBT_QTY <> 0;

SELECT PT.PROMO_POINTS,
       PT.PROCESS_DT,
       PT.ROW_ID,
       PT.MEM_NUM,
       T.TXN_NUM,
       ROWNUM
  FROM SIEBEL_PURGE.TEMP_TXN_10212015 PT
       INNER JOIN SIEBEL.S_LOY_TXN T ON PT.ROW_ID = T.ROW_ID
 WHERE     PT.PROCESS_DT BETWEEN TO_DATE ('10/18/2015', 'mm/dd/yyyy')
                             AND SYSDATE
       AND PT.PROCESS_DT IS NOT NULL
       AND PT.NUM_POINTS <> PT.TOTAL_POINTS
       AND PT.PROMO_POINTS > 0;

SELECT COUNT (*) FROM SIEBEL.EIM_LOY_ACRLIT;

SELECT * FROM SIEBEL.EIM_LOY_ACRLIT;

select * 
  FROM SIEBEL.S_LOY_ACRL_ITM
 WHERE ITEM_NUM LIKE 'PURGE%';