IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

help with syntax for using if inside sum


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jagjit

New User


Joined: 28 Dec 2006
Posts: 18
Location: india

PostPosted: Tue Jun 05, 2007 7:42 pm
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
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Tue Jun 05, 2007 8:42 pm
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: 1512
Location: Virginia, USA

PostPosted: Tue Jun 05, 2007 8:53 pm
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts calling a JCl inside a JCL JCL & VSAM 3
No new posts SRCHFOR ‘string’ command inside P... TSO/ISPF 14
No new posts To find an array of words (sys-symbol... JCL & VSAM 9
No new posts CNTL= Command Syntax Documentation CA Products 3
Search our Forums:

Back to Top