Results 1 to 5 of 5

Thread: case statement

  1. #1
    Join Date
    Jan 2005
    Posts
    80

    Unanswered: case statement

    whats wrong with this case statement?

    CASE
    WHEN BRF.COL1 = 'TRUE' THEN
    ( SUM (CASE WHEN BRF.COL2 = 'XXX' THEN
    BRF.COL3 ELSE 0 END ) -1 )
    ELSE
    ( SUM (CASE WHEN BRF.COL3 = ‘YYYY' THEN
    BRF.COL4 ELSE 0 END) )
    END OUT_COL


    The error message is

    SQL0104N An unexpected token "END" was found following "IT_Q ELSE 0 END) )".
    Expected tokens may include: ")". SQLSTATE=42601

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    The problem may not be within the snippet you provided. Please post the entire statement.

    Andy

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    I don't think you can put aggregate functions, such as SUM, in the case statement.
    ---
    "It does not work" is not a valid problem statement.

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    That is what I was suspecting, but I wanted to see the entire thing first.

    Andy

  5. #5
    Join Date
    Jan 2005
    Posts
    80
    Yes ARWinner you are right, The column BRF.COL1 i was picking was not present in the group by statement so it was genearting the errors. since the query is working fine now so i can consider that aggregation is possible in the case statements and also the case is possible with aggregation. Anyways, THanks for your help!!!

Posting Permissions

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