Query to find customers who have not purchased anything

I have a query to find customers who have purchased what we call consumables (using item property) over a given period:
SELECT T0.CardCode, T0.CardName, T0.DocDate, T0.DocTotal, T1.ItemCode, T1.Dscription,T1.quantity, T2.ItmsGrpNam
FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry, OITG T2
WHERE T0.DocDate BETWEEN '[%0]' AND '[%1]' AND T1.ItemCode like '2ssy%' AND  T2.ItmsGrpNam = 'consumable'
I have another to show customers who have a particular type of equipment:
SELECT T0.manufSN,T0.itemName,  T3.Name, T2.Address, T2.Street, T2.Block, T2.City, T2.County, T2.ZipCode
FROM OINS T0 INNER JOIN OCRD T1 ON T0.customer = T1.CardCode INNER JOIN CRD1 T2 ON T1.CardCode = T2.CardCode Inner Join OCPR T3 ON T0.ContactCod = T3.CntctCode
WHERE T0.manufSN like 'P%' AND T2.AdresType= 'S'
What I would like is to find those customers who have this equipment (query 2) but who have NOT purchased and consumables in say the last year.
I have tried using Excel by finding duplicates and taking those in query 1 from those in query 2 but it's very messy.
Has anyone done anything like this or got any good ideas?
Thanks

Hi Ralph,
Well, I enjoy teaching, so let's start at the beginning.  SQL is a fairly full-featured language, and it supports recursion and nesting.  That's why the books online often describe elements of the SQL statements as "expression" - it may be more than a field or a simple function occurring there.  Nesting is the little puppy we used here.
Now, in your first post, you said:  "What I would like is to find those customers who have this equipment (query 2) but who have NOT purchased and consumables (query 1) in say the last year."
So, our common point between the two queries is the customer, the CardCode.  That's what this part does:  F0.CardCode = T0.Customer.  In my internal convention, I used F for Filter.  So we only want the results in the filter where the CardCode matches the CardCode/Customer from the main query tables.  It's the sole contact point between the two queries.
You also said you wanted only the items where they had purchased no consumables, which basically translates into: a count of the records equals 0.  Now, since all we're interested in from the second query, the consumables query is how many records we returned, we get rid of all the columns except for one that we apply a COUNT to.  After that, it's a simple criteria:  the result of the second query has to equal 0.  This is how the criteria looks after you take out all the details and put only the important brackets in:  (SELECT COUNT...FROM...WHERE...) = 0.
This might be confusing at first, because most of the time we return recordsets from queries, but a standard feature of SQL is to return a value of any data type if the query returns a single row and a single column.  This wouldn't work at all if we had more than one column in our nested query (or would require lots of tweaking), and although it returns a number of results in the complete process of the whole SQL statement, it only returns one result for each row.
Regards,
Mark Dielmann
Edited by: Mark Dielmann on Nov 13, 2009 12:30 PM - Forum doesn't support advanced formatting on answered questions.
Edited by: Mark Dielmann on Nov 13, 2009 12:32 PM - Salutations and more formatting.
Edited by: Gordon Du on Nov 13, 2009 10:35 AM - There are maximum characters limitation for correct format

Similar Messages

  • Hi ive just noticed Debit card transaction of £14.00 to apple itunes store on the 27th march 2014 and i have not purchased anything?

    Hi ive just noticed Debit card transaction of £14.00 to apple itunes store on the 27th march 2014 and i have not purchased anything?

    How many people use your Apple ID? Anyone else in your family?
    I would immediately change your Apple ID password.

  • What a depressing experience I've had trying to upgrade to Maverick. I have the minimal requirements 10.6.8 Mountaim Lion,.. It is a continuous rerouting from Itunes store to Apple store. I have not purchased anything from the Apple store in the past and

    What a depressing experience I've had trying to upgrade to Maverick. I have the minimal requirements 10.6.8 Mountaim Lion,.. It is a continuous rerouting from Itunes store to Apple store.
    I have not purchased anything from the Apple store in the past and it is not allowing me..upgrade to Maverick
    I have even went so far to purchase a credir card hoping I could purchase an item and get an upgrade in return.  
    I'm in Taiwan and have tried to be faithful to the apple brand ..***?

    This Apple ID has not yet been used with the App Store. (also will not let me download even free apps.)
    Apple ID creation is not currently available on the Mac App Store. says: (go to itunes on your computer or ios device)

  • HT3702 I have two charges to my credit card for the same dollar amount at two different times. First on 2/27/14 & second on 3/25/14 for $4.34. today's is pending payment and last months has been removed form my account. I have not purchased anything.

    I have two charges to my credit card for the same dollar amount at two different times. First on 2/27/14 & second on 3/25/14 for $4.34. today's is pending payment and last months has been removed from my account. I have not purchased anything.

    If they are regular payments for the same amount then it sounds like you have an auto-renewing subscription - there are instructions on this page for managing and stopping them : http://support.apple.com/kb/HT4098

  • I have a charge on my bank account from Apple iTunes but I have not purchased anything in over a month!

    Earlier today I imputed my new CC information into my iTunes account so that I could update some previous apps that I had purchased. Apparently due to my previous CC Information having expired I was not able to update my previous purchases (why is that)? Also, I noticed a charge on my account from Apple iTunes but I have not make any recent purchases and I have not received any email receipts stating otherwise. Obviously I will have to cancel my debit card to prevent any further fraudulent charges. Who should I notify at Apple about this to prevent any further criminal activity against myself or others?

    You've checked the purchase history on your account via the Store > View Account menu option on your computer's iTunes, and have you got any auto-renewing subscriptions ?
    If the charge is on your newly entered card, then each time that you add or change your credit card details on your account then a small temporary store holding charge may be applied to check that the card details are correct and valid and that it's registered to exactly the same name and address as on your iTunes account - it should disappear off your account within a few days or so.
    Store holding charge : http://support.apple.com/kb/HT3702
    If it's a different charge which you don't think that you should have then you can contact iTunes Support via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • HT1933 I have been charged £5.44 from itunes but have not purchased anything. I have checked my itunes account and it shows that a purchase was made on the 15th January but doesnt say what it was.

    Hi
    I have been charged £5.44 ffrom itunes but haven't purchased anything. I have checked my itunes account and it says there was a purchase on the 15th January 13. It doesnt say what it was or how much it was for. The listings show all the apps ive downloaded whether they are free or charged but not this one from the 15th.
    Please can anyone help me find out what has happenned and how i can find out what it was for
    Thank you

    The purchase history on your acocunt should say what the item was : if you log into your account on your computer's iTunes via the Store > View Account menu option, you should then see a Purchase History section with a 'see all' link to the right of it, click on that and you should then see a list of your purchases (the most recent purchase is above the list).
    If you didn't make the purchase, and nobody else has access to your account or devices and may have made it, then try the 'report a problem' page to contact iTunes Support : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    If you didn't make the purchase then you should also change your account's password e.g. via the Store > View Account menu option on your computer's (click the Edit button to the right of your id on your account's page), by tapping on your id in Settings > iTunes & App Store on your phone, or via http://appleid.apple.com

  • Why is itunes saying i have not purchased anything on my vaoi laptop when most my apss/song were bought on this laptop?

    Itunes is asking me to answer security questions but i cant remember the awnsers and is telling me i havent previously purchased anything on this computer before but i have? Help!!!!!

    Did you ever get this settled?  I just found 3 charges on my bank statement from the last 3 days and I haven't purchased anything in over a month.  Even the ITunes store shows my last purchase as being back in early May.  But yet there are 3 separate charges on my statement dated June.  I changed my password and deleted my card but I still wnt to know how I can get my money back and how this happened.

  • Old problem I know but I cant play any of the songs in my library.tells me  cant find original  . Have not changed anything  apart from going from xp to windows 7.

    This support community is a bit new for me. Have read some old entries with the same problem but couldnt see any solutions. Libray shows all the songs ( over 2500) but I cant play any of them. Message is that itunes cant find the original.   ???? only difference is going from xp to windows 7 . can I put the songs from my ipod back on my computer maybe?

    Go into windows explorer and find out where the music is now located - in Windows 7 you have libraries for documents, music, photos and video.
    iTunes is located:
    Music
    itunes
    iTunes Media
    music
    If all the files are in that place it may just be that you have to amend a preference in iTunes:
    Edit
    Preferences
    Advanced
    ensure   Keep itunes Media organised and Copy files to iTunes Media folder when adding to library are both ticked
    Once ticked you will have a bit of a wait while iTunes re-organises the library but then your songs should all be playable again.

  • HT201359 REDEEMED MY ITUNES CARD FOR $23.75 BUT SOMEHOW ERASED FROM MY ACCOUNT AND HAVE NOT PURCHASED ANYTHING

    I BOUGHT AN ITUNES CARD FOR $23.00 AND REDEEMED IT BUT SOMEHOW IT GOT ERASED FROM MY ACCOUNT. HOW CAN I AND OR IS IT EVEN POSSIBLE TO REGAIN MY ITNES CARD FOR THE AMOUNT OF $23.00.

    https://discussions.apple.com/thread/5006462

  • Reminder email to people who have not responded to a survey

    Hi,
      I have a requirement where I need to create a survey list with multiple Questions.And send these in an email as a link. and It has to pause for couple of days, then I need to find out who has not responded to the survey, and an email has to be triggered
    only to those people.
    As of now I have added a sharepoint group called KQSO-Survey User, also added a designer workflow on Survey, which sends email to all people who are listed in KQSO-Survey User, and It Pauses for 2 days.
    But I am not really sure How do I find people from KQSO-Survey Group who have not responded to the survey and send only those users a reminder email. 
    Any Help would be greatly appreciated.
    Thanks,
    Poonam

    Hi Poonam,
    You don't have to traverse through the SP Group to find people who have not filled the survey. You can look at the Tasks list. Once a task is completed, workflow is going to mark the Status as Completed. If you first group them by the Related Item, then
    by Status, it will show you those who have completed and those that haven't for a particular Survey that you send out.
    Remember that completing the survey and completing a task would be two separate things that users might have to do. This is my understanding.
    Regards, Kapil ***Please mark answer as Helpful or Answered after consideration***

  • How to find vendor who does not have transactions for last one year

    HI all,
    We have around 20000 vendors, i want to find out who does not have any transactions for last 1 year.  Any valuable suggestions on this?
    Thanks and regards
    Ramarao

    HI,
    Actually above one mehtod is very painful method. Is there any method by writing ABAP query and any other short cut method
    Thanks and regards
    Ram

  • Customer Query to idetify customers that does not have any transactions

    Dear All,
    I am using the following query to find out the customers that does not have any transactions in the system:
    SELECT customer_number, customer_name, DECODE(status,'A','ACTIVE') current_status
    --count(*)
    FROM ra_customers
    WHERE customer_id NOT IN (select distinct bill_to_customer_id from ra_customer_trx_all)
    ORDER BY customer_name ASC
    Is this right?
    The above query is to identify those customers that were added by mistake and that does not have any transactions been done.
    Please update...
    Many thanks in advance...

    santark wrote:
    Dear All,
    I am using the following query to find out the customers that does not have any transactions in the system:>
    SELECT customer_number, customer_name, DECODE(status,'A','ACTIVE') current_status
    --count(*)
    FROM ra_customers
    WHERE customer_id NOT IN (select distinct bill_to_customer_id from ra_customer_trx_all)
    ORDER BY customer_name ASC
    You are will only see customers which have not been BILL TO there could be SHIP TO Customers as well hence look out for all the usages of customers in the AR transactions to get the query right.
    Is this right?
    The above query is to identify those customers that were added by mistake and that does not have any transactions been done.
    Please update...
    Many thanks in advance...Thanks

  • I have downloaded mountain lion from the app store on another computer.  I have then gone to find it in "purchases" in the app store on my own macbook pro and it just comes up as "you have not purchased any apps" how to I get my mountain lion?

    I have downloaded mountain lion from the app store on another computer.  I have then gone to find it in "purchases" in the app store on my own macbook pro and it just comes up as "you have not purchased any apps" how to I get my mountain lion?

    Mac App Store: Hiding and unhiding purchases
              http://support.apple.com/kb/HT4928

  • Need a way to find out users who have not all logged in into the portal

    Hi all,
    Please can some body tell me the way to find out all the users who have not at all logged in into the SAP enterprise portal after their user ID's are created.
    Are there any methods(UME APIs) or attributes that set the status of user whether he/she has logged in into the portal first time.
    Thanks & Regards,
    Hajira Rehman

    There used to be a way, but here's what Detlev posted earlier this year:
    <b>Hi everyone,
    UPDATE on this: From SP16 on, the last successful login date does not get logged into the database anymore, see <a href="http://help.sap.com/saphelp_nw04/helpdata/en/43/bc6b9202454dece10000000a422035/frameset.htm">here</a> - for performance reasons, as it is stated...
    Hope it helps not to fall into this new trap
    Detlev</b>
    So, there are no simple APIs - you'll need to build your own mechanism.

  • Why does Adobe not inform customers who have iPhones below 5 that Reader is not compatible until very near the end after WASTING customer's time? BIG NEGATIVE from here

    Why does Adobe not inform customers who have iPhones below 5 that Reader is not compatible until very near the end after WASTING customer’s time? BIG NEGATIVE from here

    When you view an App in the App Store or iTunes Store, the listing will show what iOS versions are supported by the app.
    See this posting:
    How do I get a version of Adobe Reader for an IPod touch with IOS 6.1.6

Maybe you are looking for