SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql where exists and
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

angela_g
Starting Member

United Kingdom
17 Posts

Posted - 03/05/2014 :  07:50:57  Show Profile  Reply with Quote
Hi I am trying to add to existing SQL for an insert in to an Oracle application Express application. This is the existing code

INSERT INTO RE_EZPAY_AT_AGENCY_DAILY
    (SNAPSHOT_DATE,
     MEMBER_NO_WCD,
     MEMBER_NO,
     RPT_GROUP,
     AGG_ORDER_NO,
     STATUS,
     DEBT,
     NUMBER_INSTALMENTS)
    SELECT
      VE_EZP_AT_AGENCY_DAILY.SNAPSHOT_DATE,
      VE_EZP_AT_AGENCY_DAILY.MEMBER_NO_WCD,
      VE_EZP_AT_AGENCY_DAILY.MEMBER_NO,
      VE_MEMBER_MERCH_MAX_ORDER_AMT.MERCH_GROUP,
      VE_EZP_AT_AGENCY_DAILY.AGG_ORDER_NO,
      DECODE(SIGN(SYSDATE-VE_MEMBER.MEMBER_JOIN_DATE-365),1,'R','O') AS STATUS,
      (SELECT SUM(VE_EZP_ORDER_TRANS.EZP_INSTALL_TOTAL_AMT)
       FROM VE_EZP_ORDER_TRANS
       WHERE VE_EZP_ORDER_TRANS.MEMBER_NO = VE_EZP_AT_AGENCY_DAILY.MEMBER_NO
     AND ((VE_EZP_ORDER_TRANS.EZP_BILL_STATUS = 'AT')
       OR (VE_EZP_ORDER_TRANS.EZP_BILL_STATUS   = 'WB'))
       GROUP BY VE_EZP_AT_AGENCY_DAILY.SNAPSHOT_DATE, 
       VE_EZP_AT_AGENCY_DAILY.MEMBER_NO_WCD, 
       VE_EZP_AT_AGENCY_DAILY.MEMBER_NO, 
       VE_EZP_AT_AGENCY_DAILY.AGG_ORDER_NO, 
       DECODE(SIGN(SYSDATE-VE_MEMBER.MEMBER_JOIN_DATE-365),1,'R','O')
      ) AS DEBT,
      (SELECT COUNT(VE_EZP_ORDER_TRANS.EZP_INSTALL_TOTAL_AMT)
       FROM VE_EZP_ORDER_TRANS
       WHERE VE_EZP_ORDER_TRANS.MEMBER_NO=VE_EZP_AT_AGENCY_DAILY.MEMBER_NO
       AND VE_EZP_ORDER_TRANS.EZP_BILL_STATUS IN ('AT','WB')
      ) AS NUMBER_INSTALMENTS
    FROM VE_EZP_AT_AGENCY_DAILY
    JOIN VE_MEMBER ON VE_EZP_AT_AGENCY_DAILY.MEMBER_NO = VE_MEMBER.MEMBER_NO
    JOIN VE_MEMBER_MERCH_MAX_ORDER_AMT ON (VE_MEMBER_MERCH_MAX_ORDER_AMT.MEMBER_NO = VE_EZP_AT_AGENCY_DAILY.MEMBER_NO)
    WHERE ((NOT EXISTS (SELECT 1 FROM RE_EZPAY_AT_AGENCY_DAILY WHERE VE_EZP_AT_AGENCY_DAILY.MEMBER_NO=RE_EZPAY_AT_AGENCY_DAILY.MEMBER_NO))
    AND VE_EZP_AT_AGENCY_DAILY.SNAPSHOT_DATE > (SELECT MAX (SNAPSHOT_DATE) from RE_EZPAY_AT_AGENCY_DAILY))
    AND VE_MEMBER_MERCH_MAX_ORDER_AMT.RANK_NUM = 1
    ;

I want to also insert records where every member has a status of 'c' or status is not = 'H','R', 'O' but already exists. I am only trying to prevent duplicate records being added which havn't yet been closed ('c').

Thanks!!

Edited by - angela_g on 03/05/2014 09:11:22

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1052 Posts

Posted - 03/05/2014 :  08:00:55  Show Profile  Reply with Quote
This forum is for SQL server, and the query shows that you're working in Oracle. May be you should post oracle question in some relevant forums.


bye the way if the query is working correctly and you want only to insert it into some existing table. following might help you..

INSERT INTO TableName (columnName1, columnName2,...,ColumnNameN)
SELECT query

Cheers
MIK
Go to Top of Page

angela_g
Starting Member

United Kingdom
17 Posts

Posted - 03/05/2014 :  09:10:40  Show Profile  Reply with Quote
Thanks MIK!
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1052 Posts

Posted - 03/05/2014 :  09:43:41  Show Profile  Reply with Quote
you're welcome!

Cheers
MIK
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000