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

dynamic SQL with SUM


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

New User


Joined: 03 Nov 2005
Posts: 33

PostPosted: Tue Feb 12, 2008 4:10 pm
Reply with quote

I have to group record based on a certain condition and then there is an amount which comes against each group. For each group i should also have the percentage of this amount when compared to total amount.

Example:
123 100.00 6.66
456 900.00 60
789 500.00 33.33

the 6.66, 60 and 33.33 are the percentage of totals 100, 900 and 500 against the total amount of 1500(100+900+500)

I have used group by and sum to get the totals for each set and to group by the ID
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Tue Feb 12, 2008 9:01 pm
Reply with quote

And your question is?
I don't think you can do this with a simple DB2 query, since you are looking for a percentage of the total, that will require two queries and some way of saving the total amount....COBOL?
Back to top
View user's profile Send private message
divya_maddi

New User


Joined: 03 Nov 2005
Posts: 33

PostPosted: Wed Feb 13, 2008 12:08 pm
Reply with quote

yes cics guy... exactly what i am looking for... the first quert i have used gives me the sum total for all record (1500) in this case
the second query gives me the sums for each group which is 100, 900 and 500 in this case.... now what i want is how do i save or use the first sum total to use it in the second query... i am using dynamic SQL(cannot be changed)... hence i want to know if there is any way of storing that value for use in the second query
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Feb 13, 2008 8:35 pm
Reply with quote

Hello,

Quote:
hence i want to know if there is any way of storing that value for use in the second query
Yes. As suggested, save the value(s) in COBOL code.
Back to top
View user's profile Send private message
divya_maddi

New User


Joined: 03 Nov 2005
Posts: 33

PostPosted: Fri Feb 22, 2008 12:57 pm
Reply with quote

i cannot use COBOL as per the requirement
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Feb 22, 2008 8:15 pm
Reply with quote

Hello,

Quote:
i cannot use COBOL as per the requirement


What business requirement dictates this?
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 Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts JCL Dynamic System Symbols JCL & VSAM 3
No new posts Synctool-dynamic split job for varyin... JCL & VSAM 7
No new posts Dynamic file allocation using JCL JCL & VSAM 8
No new posts Dynamic Sortin DD cards SYNCSORT 8
Search our Forums:

Back to Top