MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Adjustment Amounts

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
nag77
Beginner


Joined: 03 Jan 2006
Posts: 11
Topics: 8

PostPosted: Fri Feb 24, 2006 12:27 am    Post subject: Adjustment Amounts Reply with quote

Hi,

I have to get the sum of the amounts for an account number till the current year. The conditions are that all amounts with Indicator = 'C' should be added and all the amounts with Indicator = 'D' should be subtracted.

Can u suggest a query for these conditions.

thanks
Nag
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12382
Topics: 75
Location: San Jose

PostPosted: Fri Feb 24, 2006 6:18 am    Post subject: Reply with quote

nag77,

Try this untested sql

Code:

SELECT SUM(CASE WHEN IND = 'C' THEN AMT       
                WHEN IND = 'D' THEN AMT * -1 
                ELSE 0                       
           END)                               
  FROM TABLE;                                   


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Thu Mar 02, 2006 1:40 am    Post subject: Reply with quote

Nag,

I guess you are looking for a scenario like below:


Code:

CREATE TABLE SHEKAR.AMOUNTS                 
(                                           
 INDICATOR   CHAR(1) NOT NULL,               
 AMOUNT      INTEGER NOT NULL               
)                                           
IN DBTEMP.TBTEMP;                           
INSERT INTO SHEKAR.AMOUNTS VALUES ('C',1000);
INSERT INTO SHEKAR.AMOUNTS VALUES ('D',500);
INSERT INTO SHEKAR.AMOUNTS VALUES ('C',1000);
INSERT INTO SHEKAR.AMOUNTS VALUES ('C',100);
INSERT INTO SHEKAR.AMOUNTS VALUES ('D',1000);
INSERT INTO SHEKAR.AMOUNTS VALUES ('D',500);
INSERT INTO SHEKAR.AMOUNTS VALUES ('C',500);
INSERT INTO SHEKAR.AMOUNTS VALUES ('D',1000);
INSERT INTO SHEKAR.AMOUNTS VALUES ('C',1000);
INSERT INTO SHEKAR.AMOUNTS VALUES ('C',1111);
SELECT SUM(CASE WHEN INDICATOR = 'C' THEN AMOUNT     
                WHEN INDICATOR = 'D' THEN AMOUNT * -1
                ELSE 0                               
       END)                       
FROM SHEKAR.AMOUNTS;


OUTPUT

Code:

       -------------- C --------------------     ---------- D ----------
1711 [(1000 + 1000 + 100 + 500 + 1000 + 1111) - (500 + 1000 + 500 + 1000)]


_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group