Select and Count not working.....HELP PLEASE!!

I have the following scenerio:
SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE 'AN101011%' AND #RECDT BETWEEN 19970826 AND 20020826 GROUP BY #PART,#PDESC
//brings back count of 1 which is right...only one part within the date range
PCOUNT: 1
SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE 'AC043208%' OR #PART LIKE 'AN101011%' AND #RECDT BETWEEN 19970826 AND 20020826 GROUP BY #PART,#PDESC
//looped through result set and these two counts are right
PCOUNT: 1
PCOUNT: 1
SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE 'AN101011%' OR #PART LIKE 'AC043208%' AND #RECDT BETWEEN 19970826 AND 20020826 GROUP BY #PART,#PDESC
//now brings back a pcount of 2 for the first part which is shouldn't, there are two parts with the same number but only one which falls within the date range.
PCOUNT: 2
PCOUNT: 1
could anyone help me with this.....thanks in advance

Found the solution....its in the order of processing of the select statement...for others future reference....
SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE 'AN101011%' AND #RECDT BETWEEN 19970826 AND 20020826 GROUP BY #PART,#PDESC
//brings back count of 1 which is right...only one part within the date range
PCOUNT: 1
SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE 'AC043208%' OR #PART LIKE 'AN101011%' AND #RECDT BETWEEN 19970826 AND 20020826 GROUP BY #PART,#PDESC
//looped through result set and these two counts are right
PCOUNT: 1
PCOUNT: 1
//*****this works because in actual fact it is reading the date range and it associates it with the last part number so it reads it like this (note the brackets):
SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE 'AC043208%' OR (#PART LIKE 'AN101011%' AND #RECDT BETWEEN 19970826 AND 20020826) GROUP BY #PART,#PDESC
SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE 'AN101011%' OR #PART LIKE 'AC043208%' AND #RECDT BETWEEN 19970826 AND 20020826 GROUP BY #PART,#PDESC
//now brings back a pcount of 2 for the first part which is shouldn't, there are two parts with the same number but only one which falls within the date range.
PCOUNT: 2
PCOUNT: 1
//***this did not work because the date range only applied to the last part number not the first..so it read it like (note the brackets):
SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE #PART LIKE 'AN101011%' OR (#PART LIKE 'AC043208%' AND #RECDT BETWEEN 19970826 AND 20020826) GROUP BY #PART,#PDESC
//**Therefore, I changed it to (including the brackets) and it ran fine:
SELECT #PART,#PDESC,COUNT(#PART) AS PCOUNT FROM MYLIB WHERE (#PART LIKE 'AN101011%' OR #PART LIKE 'AC043208%') AND #RECDT BETWEEN 19970826 AND 20020826 GROUP BY #PART,#PDESC

Similar Messages

Maybe you are looking for

  • Anyone know how to get Adobe to pay attention? Or am I compelled to be a pirate?

    I bought PageMaker many many years ago (about 1998 I think), and at the time it was a substantial investment. I've upgraded regularly since, and now have InDesign CS3 purchased in June 2007 (Adobe Store Australia Recept No. AD000385242U dated 27/6/07

  • Creation of ACH pmt advice for EU C.Cd (PMW activated)

    Hi experts, I'm a little at loss with my 1st dealings with the payment medium workbench. I got a requirement to setup payment advice a EU company code that currently sends out ACH payments without advice. Currently In FBZP, 1- The EU CCd is a paying

  • ... Jobs Schedules in Oracle

    Dear All, Our business requirement is such that we need to process some data in the morning till lunch , and after lunch that data is useless for us. Is there any way we can schedule a JOB in oracle , so that on a specific time , it will delete aroun

  • Store art 1TB 3,5" doesn't work on Windows 7

    Hi, I was using my HDD for about half an hour on Windows xp OS and everything was OK. When I installed new Windows 7 x64 I have a problem. Windows detect a HDD, but i can't send there any files. I formated it, but it doesn't help. Can someone help me

  • When will the Mac OS get some color ?

    .. I am really getting bored with all the GREY !