Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    46

    Unanswered: 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.

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    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')

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •