Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with join 1

Status
Not open for further replies.

nohandlesleft254

IS-IT--Management
Apr 19, 2006
58
GB
Hi,

I'm using the below query to get invoices from my DB. What I want to do is only get invoices that dont have a payment against them in the joined 'receipts' table (e.g. where receipts.invoicenr = ''). Yet i cant seem to arrange the query to give me that result. Any suggestions?

Thanks

PS: Effectively what i want to say is ON SALESINVOICES.SerNr <> RECEIPTSROW.InvoiceNr

<cfquery name="Ledgeractive" datasource="#Application.HansaData#">
SELECT
SALESINVOICES.SerNr,
SALESINVOICES.InvDate,
SALESINVOICES.CustOrdNr,
SALESINVOICES.Sum4,
SALESINVOICES.InvType,
SALESINVOICES.CustCode,
SALESINVOICES.OKFlag,
SALESINVOICES.PayDeal,
SALESINVOICES.PayDate,
RECEIPTSROW.PayDate AS Paydate2,
RECEIPTSROW.InvoiceNr,
RECEIPTSROW.RecVal,
RECEIPTSROW.CustCode
FROM RECEIPTSROW
LEFT JOIN SALESINVOICES
ON SALESINVOICES.SerNr=RECEIPTSROW.InvoiceNr
WHERE SALESINVOICES.CustCode = '#Session.CompanyID#'
AND (SALESINVOICES.InvDate LIKE '%#Session.LedgerQuickfind#%'
OR SALESINVOICES.SerNr LIKE '%#Session.LedgerQuickfind#%'
OR SALESINVOICES.CustOrdNr LIKE '%#Session.LedgerQuickfind#%'
OR SALESINVOICES.Sum4 LIKE '%#Session.LedgerQuickfind#%'
OR SALESINVOICES.InvType LIKE '%#Session.LedgerQuickfind#%')

ORDER BY
<cfswitch expression="#sort#">
<cfcase value="1">
CONVERT(DATETIME, SALESINVOICES.InvDate, 130) DESC
</cfcase>
<cfcase value="2">
CONVERT(DATETIME, SALESINVOICES.InvDate, 130) ASC
</cfcase>
<cfcase value="3">
CAST(SALESINVOICES.SerNr AS NUMERIC) DESC
</cfcase>
<cfcase value="4">
CAST(SALESINVOICES.SerNr AS NUMERIC) ASC
</cfcase>
<cfcase value="5">
SALESINVOICES.CustOrdNr DESC
</cfcase>
<cfcase value="6">
SALESINVOICES.CustOrdNr ASC
</cfcase>
<cfcase value="7">
CAST(SALESINVOICES.Sum4 AS NUMERIC) DESC
</cfcase>
<cfcase value="8">
CAST(SALESINVOICES.Sum4 AS NUMERIC) ASC
</cfcase>
<cfcase value="9">
SALESINVOICES.InvType DESC
</cfcase>
<cfcase value="10">
SALESINVOICES.InvType ASC
</cfcase>
</cfswitch>
</cfquery>
 
Is it sql server?

--Get Invoices where there is no receipt for that invoice

select si.*, rr.InvoiceNr
from SALESINVOICES si
left outer join RECEIPTSROW rr on si.SerNr = rr.InvoiceNr
where rr.InvoiceNr is null
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top