Below are two queries which if combined with a UNION give me all customers who are overdue OR have purchased Floor Plans.
I need to modify this query to pull all customers which are Overdue AND have purchased floor plans. The ANSI-SQL Intersect command would work perfectly however I am unsure how to modify this using T-SQL syntax to achieve the desired result. Any takers?
SELECT CustomerRef_ListID FROM Invoice INNER JOIN StandardTerms ON Invoice.TermsRef_ListID = StandardTerms.ListID WHERE Invoice.DueDate < DateDiff('d',StandardTerms.StdDueDays,Now())
UNION SELECT CustomerRef_ListID FROM Invoice WHERE Invoice.TermsRef_ListID is Null AND Invoice.DueDate < Now()
UNION
SELECT CustomerRef_ListID FROM SalesReceipt INNER JOIN SalesReceiptLineDetail ON SalesReceipt.TxnID = SalesReceiptLineDetail.IDKEY WHERE ItemRef_FullName = 'Floor Plans'
UNION SELECT DISTINCT CustomerRef_ListID FROM Invoice INNER JOIN InvoiceLineDetail ON Invoice.TxnID = InvoiceLineDetail.IDKEY WHERE ItemRef_FullName = 'Floor Plans';
I need to modify this query to pull all customers which are Overdue AND have purchased floor plans. The ANSI-SQL Intersect command would work perfectly however I am unsure how to modify this using T-SQL syntax to achieve the desired result. Any takers?
SELECT CustomerRef_ListID FROM Invoice INNER JOIN StandardTerms ON Invoice.TermsRef_ListID = StandardTerms.ListID WHERE Invoice.DueDate < DateDiff('d',StandardTerms.StdDueDays,Now())
UNION SELECT CustomerRef_ListID FROM Invoice WHERE Invoice.TermsRef_ListID is Null AND Invoice.DueDate < Now()
UNION
SELECT CustomerRef_ListID FROM SalesReceipt INNER JOIN SalesReceiptLineDetail ON SalesReceipt.TxnID = SalesReceiptLineDetail.IDKEY WHERE ItemRef_FullName = 'Floor Plans'
UNION SELECT DISTINCT CustomerRef_ListID FROM Invoice INNER JOIN InvoiceLineDetail ON Invoice.TxnID = InvoiceLineDetail.IDKEY WHERE ItemRef_FullName = 'Floor Plans';