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 > case statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-08-07, 11:48
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Jan 2005
Posts: 75
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
Reply With Quote
  #2 (permalink)  
Old 06-08-07, 13:58
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The problem may not be within the snippet you provided. Please post the entire statement.

Andy
Reply With Quote
  #3 (permalink)  
Old 06-08-07, 15:44
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I don't think you can put aggregate functions, such as SUM, in the case statement.
Reply With Quote
  #4 (permalink)  
Old 06-08-07, 16:18
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
That is what I was suspecting, but I wanted to see the entire thing first.

Andy
Reply With Quote
  #5 (permalink)  
Old 06-09-07, 06:07
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
 
Join Date: Jan 2005
Posts: 75
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!!!
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