Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
help with syntax for using if inside sum

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
Author Message
jagjit

New User


Joined: 28 Dec 2006
Posts: 4
Location: india

PostPosted: Tue Jun 05, 2007 7:42 pm    Post subject: help with syntax for using if inside sum
Reply with quote

SELECT SUM (IF CASE_PASTDUE > 0
SET CASE_PASTDUE TO CASE_PASTDUE
ELSE SET 0 TO CASE_PASTDUE)

FROM DB2TEST.SPLIT_DETAIL
WHERE SPLIT_TRANS_ID = 10
AND SPLIT_LEVEL = 22;
Back to top
View user's profile Send private message
References
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 185
Location: Chennai

PostPosted: Tue Jun 05, 2007 8:42 pm    Post subject: Re: help with syntax for using if inside sum
Reply with quote

I am not clear of your requirement but seeing the sql why can't the CASE_PASTDUE be used with the WHERE clause? icon_confused.gif

Anyway for SUM syntax is,
Select SUM (column name) AS < variable>
from <table name>
Where <condition>
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 989
Location: Virginia, USA

PostPosted: Tue Jun 05, 2007 8:53 pm    Post subject: Re: help with syntax for using if inside sum
Reply with quote

jagjit wrote:
SELECT SUM (IF CASE_PASTDUE > 0
SET CASE_PASTDUE TO CASE_PASTDUE
ELSE SET 0 TO CASE_PASTDUE)

FROM DB2TEST.SPLIT_DETAIL
WHERE SPLIT_TRANS_ID = 10
AND SPLIT_LEVEL = 22;


Look up the format for the CASE statement in the sql manual.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1