I have the following query which returns information to me on whether a user has gone from just being a user to a customer in our system. Here's the SQL:
SELECT AM_invoiceheader.BuyerID, COUNT(DISTINCT AM_invoiceitems.InvoiceID) AS Invoices, SUM(AM_invoiceitems.SalePrice) AS Revenue,
YEAR(AM_invoiceheader.ShipDate) AS Year, SUM(AM_invoiceitems.Quantity) AS Units, AM_buyers.BillToEmail, AM_buyers.ShipToEmail
FROM AM_invoiceheader INNER JOIN
AM_invoiceitems ON AM_invoiceheader.InvoiceID = AM_invoiceitems.InvoiceID INNER JOIN
AM_buyers ON AM_invoiceheader.BuyerID = AM_buyers.BuyerID
WHERE (AM_invoiceitems.Typeid IN (1)) AND (AM_invoiceheader.InvoiceSourceID IN (5, 6)) OR
(AM_invoiceitems.Typeid IN (1)) AND (AM_invoiceheader.InvoiceSourceID IN (5, 6))
GROUP BY AM_invoiceheader.BuyerID, YEAR(AM_invoiceheader.ShipDate), AM_buyers.BillToEmail, AM_buyers.ShipToEmail
HAVING (AM_buyers.BillToEmail LIKE Nfirstname.lastname@example.org') OR
(AM_buyers.ShipToEmail LIKE Nemail@example.com')
ORDER BY AM_invoiceheader.BuyerID
I have 17k of email addresses that I need to run through this query, and I am hoping there is a way for me to be able to do this in just a T-SQL query by way of a SQL Agent Job or some other batch process (other than SSIS - long story for why I am avoiding that method).
Please let me know if you need additional information from me to help out, and any and all help is definitely appreciated!
Thank you in advance...