Results 1 to 15 of 19

Thread: SQL sets query

Threaded View

  1. #1
    Join Date
    Mar 2003
    Location
    NJ/NY
    Posts
    17

    SQL sets query

    PLEASE SEE my update (post #3) for a better simpler explanation!!!!!

    Hi,
    I need a query which is basically

    (query 1)
    Except
    (query 2)

    SQL server supports
    (query 1)Union (query 2)
    but I can't get the Except to work.

    Alternatively,
    I also tried to implement it by using the "NOT IN" but didnt work.
    Background: 3 tables, accnts, Opty, Opty_postn
    I want
    the accounts who have 1 or more opty's at 100% (sold) before 1/1/2002 but zero opty's at 100% after 12/31/2001.
    accnts has fields ID & name, ROW_ID
    opty has fields acct_id, prob, ROW_ID
    opty_postn has fields opty_id, close_dt

    My query:
    SELECT accnt.name
    FROM accnt
    WHERE
    accnt.ROW_ID IN
    (
    SELECT acct_id
    FROM opty
    where prob = 100
    AND opty.ROW_ID IN
    (SELECT opty_id
    FROM opty_postn
    WHERE close_dt<1/1/2002)
    )
    AND accnt.ROW_ID NOT IN
    (
    SELECT acct_id
    FROM opty
    where prob = 100
    AND opty.ROW_ID IN
    (SELECT opty_id
    FROM opty_postn
    WHERE close_dt >12/31/2001)
    )
    AND accnt.ROW_ID = opty.accnt_ID

    my intent was
    select account.names
    where id
    is in set(prob = 100 & sale before 1/1/02)
    but not in ( prob = 100 & sale after 21/31/01)
    SO ,the accounts which have sales both before and after get counted. But I want only those accoutns which have sales only before 1/1/02.
    I hope i explained this right.
    Thanks in advance for your help.

    Ash.
    Last edited by ashish9393; 04-21-2003 at 06:24 PM.

Posting Permissions

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