If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > What am I Missing in My Logic?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-20-09, 11:28
rockdave35 rockdave35 is offline
Registered User
 
Join Date: Jan 2009
Posts: 43
What am I Missing in My Logic?

Hey guys,

I am trying to write a query that will list people who have received payments up till Jan 31th. I don't want to see people who received payments after Jan 31.

I'm missing something with my logic because it returns ppl who have payments in Jan but also after Jan 31th. Here is part of my query:

WHERE ANTY_PYMT_DT BETWEEN '2009-01-01' AND '2009-01-31'
AND ANTY_PYMT_DT NOT BETWEEN '2009-01-31' AND -2009-03-31'

03-01-09 is the last payment date that anyone would have received. But this query still pulls this one guy who has both a Jan date and a date of 03-01-09. I even tried <> '2009-03-01' and it still pulls the guy.
Reply With Quote
  #2 (permalink)  
Old 03-20-09, 11:54
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Please try:

Code:
  FROM <your_table> AS A
 WHERE ANTY_PYMT_DT BETWEEN '2009-01-01' AND '2009-01-31'
   AND NOT EXISTS
       (SELECT *
          FROM <your_table> AS B
         WHERE B.people_id = A.people_id
           AND B.ANTY_PYMT_DT > '2009-01-31')
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On