Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2013
    Posts
    8

    Unanswered: CASE Statement Problem

    Having a problem figuring out this case statement after the Where in my SQL Query. maybe a case statement isnt the way to go.

    SELECT TRUNC (SYSDATE),
    DODI,
    DOD,
    ACCT_CD,
    SUM (LOT) QTY
    FROM WARSDB.QANSN_DATA
    WHERE PUR<> 'I'
    AND TRIM (DODI) IS NOT NULL
    AND COND IN ('A', 'B', 'C', 'D')
    AND CASE
    WHEN DOD IN
    ('W53XMD', 'W22PVK', 'W44XMF', 'W67G23', 'W25G1R')
    THEN
    ACCT_CD IN ('TRA', 'MAA', ' ')
    ELSE
    Q1.ACCT_CD IN ('TRA', 'MAA')
    END
    GROUP BY DODI
    Q1.DOD
    Q1.ACCT_CD

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    It looks like you are working with Oracle, rather than SQL Server.

    Besides, that, in either RDBMS, CASE returns a value, it does not take an action as in other procedural languages.

    I think you want something more like
    Code:
     and ((DOD in ('W53XMD', 'W22PVK', 'W44XMF', 'W67G23', 'W25G1R') and ACCT_CD IN ('TRA', 'MAA', ' '))
    or ACCT_CD IN ('TRA', 'MAA'))

  3. #3
    Join Date
    Apr 2013
    Posts
    8
    Sorry, yes i posted this in the area. I will post in the Oracle forum. Your answer isnt what i am looking for. I need all DOD but when the DOD IN ('W53XMD', 'W22PVK', 'W44XMF', 'W67G23', 'W25G1R') I only want ACCT_CD IN (' ',TRA','MAA') ELSE i only want TRA and MAA.

Posting Permissions

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