Results 1 to 2 of 2

Thread: Help with a Custom Query

  1. #1
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Help with a Custom Query

    Hi,

    I'm trying to run the following query. What I want to acheive is that where they is no record matching the Where clause for the payments I want it to still include the opportunity and show 0 as the payment amount as it refers to payments taken this year. If I remove the Data part of the where clasue it returns the Opportunity with the Payment information for a Payment that is taken last year, but how can I show the Opportunity Information when there is nothing matching in the Payments?

    Code:
    SELECT o.NAME, oc.pr_account_no_c,p.payment_amount,pc.payment_date_c,p.payment_status,p.id 
    FROM opportunities o  
    	INNER JOIN opportunities_cstm oc ON o.id = oc.id_c  
    	INNER JOIN accounts_opportunities ao ON o.id=ao.opportunity_id AND ao.deleted=0  
    	INNER JOIN accounts a ON a.id=ao.account_id AND a.deleted=0 
    	LEFT JOIN accounts_pr_pr_payments_c ap ON a.id = ap.accounts_p6053ccounts_ida 
    	LEFT JOIN pr_pa_pr_payments p ON p.id = ap.accounts_pf9c2ayments_idb 
    	INNER JOIN pr_pa_pr_payments_cstm pc ON p.id = pc.id_c 
    WHERE oc.pr_account_no_c = '7801084' 
    	AND p.payment_status = 'PAID' 
    	AND (pc.payment_date_c >='2011-01-01 00:00:00' AND pc.payment_date_c<='2011-12-31 23:59:59')
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  2. #2
    christianknoll's Avatar
    christianknoll is offline Sugar Community Member
    Join Date
    Nov 2008
    Location
    Vienna
    Posts
    939

    Default Re: Help with a Custom Query

    Do a left join on the payments_cstm table as well (and in the future you might want to do this using standard vardefs extensions and not the sutdio ... ;-)

    christian.

    Quote Originally Posted by chrislynch8 View Post
    Hi,

    I'm trying to run the following query. What I want to acheive is that where they is no record matching the Where clause for the payments I want it to still include the opportunity and show 0 as the payment amount as it refers to payments taken this year. If I remove the Data part of the where clasue it returns the Opportunity with the Payment information for a Payment that is taken last year, but how can I show the Opportunity Information when there is nothing matching in the Payments?

    Code:
    SELECT o.NAME, oc.pr_account_no_c,p.payment_amount,pc.payment_date_c,p.payment_status,p.id 
    FROM opportunities o  
    	INNER JOIN opportunities_cstm oc ON o.id = oc.id_c  
    	INNER JOIN accounts_opportunities ao ON o.id=ao.opportunity_id AND ao.deleted=0  
    	INNER JOIN accounts a ON a.id=ao.account_id AND a.deleted=0 
    	LEFT JOIN accounts_pr_pr_payments_c ap ON a.id = ap.accounts_p6053ccounts_ida 
    	LEFT JOIN pr_pa_pr_payments p ON p.id = ap.accounts_pf9c2ayments_idb 
    	INNER JOIN pr_pa_pr_payments_cstm pc ON p.id = pc.id_c 
    WHERE oc.pr_account_no_c = '7801084' 
    	AND p.payment_status = 'PAID' 
    	AND (pc.payment_date_c >='2011-01-01 00:00:00' AND pc.payment_date_c<='2011-12-31 23:59:59')

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Custom Query
    By dvelguru in forum Feature Requests
    Replies: 1
    Last Post: 2010-01-03, 05:15 PM
  2. Custom query for list view in custom module
    By precar in forum Developer Help
    Replies: 3
    Last Post: 2009-06-15, 04:01 AM
  3. Custom on custom query view....
    By mcnudox in forum Developer Help
    Replies: 1
    Last Post: 2009-03-29, 03:25 PM
  4. Custom query on custom view (List)
    By jasv in forum Developer Help
    Replies: 4
    Last Post: 2009-02-09, 10:36 AM
  5. Custom query in Custom Dashboard module
    By tbivans in forum Developer Help
    Replies: 11
    Last Post: 2007-03-05, 07:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •