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 

Query for reconciliation report

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


Joined: 23 Mar 2005
Posts: 17
Topics: 7

PostPosted: Thu Jun 02, 2005 5:46 am    Post subject: Query for reconciliation report Reply with quote

Hi,

Please help me to write the following query

Consider following table.

ACCTFIN
Code:

ACCOUNT   ID   SEQ_NO   SHRS   DOLS
A         M        1     100   100
B         M        2     200   200
A         P        1     100   100
C         P        3     300   300


Output should be
Code:

ACCOUNT   SEQ_NO   M_SHRS   M_DOLS   P_SHRS   P_DOLS

A             1       100      100      100      100
B             2       200      200        0        0
C             3         0        0      300      300

Note:
If ID = 'M' and SHRS not null then return M_SHRS else 0
If ID = 'P' and SHRS not null then return P_SHRS else 0
If ID = 'M' and DOLS not null then return M_DOLS else 0
If ID = 'P' and DOLS not null then return P_DOLS else 0


Thanks in advance,
Showkath
_________________
Regards,
Showkath
-----------------------------------------------------
Our opinions do not really blossom into fruition until we have expressed them to someone else - Mark Twain
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Jun 02, 2005 7:18 am    Post subject: Reply with quote

Showkath,

Try this sql. I assumed that SHRS and DOLS columns are defined as decimal columns.

Code:

SELECT A.ACCOUNT                                                     
      ,A.SEQ_NO                                                     
      ,SUM(A.M_SHRS) M_SHRS                                         
      ,SUM(A.M_SHRS) M_DOLS                                         
      ,SUM(A.P_SHRS) P_SHRS                                         
      ,SUM(A.P_SHRS) P_DOLS                                         
  FROM (SELECT ACCOUNT                                               
              ,SEQ_NO                                               
              ,CASE ID WHEN 'M' THEN SHRS ELSE DECIMAL(0) END  M_SHRS
              ,CASE ID WHEN 'M' THEN DOLS ELSE DECIMAL(0) END  M_DOLS
              ,CASE ID WHEN 'P' THEN SHRS ELSE DECIMAL(0) END  P_SHRS
              ,CASE ID WHEN 'P' THEN DOLS ELSE DECIMAL(0) END  P_DOLS
          FROM ACCTFIN) A 
 GROUP BY A.ACCOUNT
         ,A.SEQ_NO
  ;                 


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
showkath
Beginner


Joined: 23 Mar 2005
Posts: 17
Topics: 7

PostPosted: Thu Jun 02, 2005 7:23 am    Post subject: Reply with quote

kOLUSU,

Thanks for ur prompt reply. That query is working as per the requirement. Thanks a lot.

Regards,
Showkath
_________________
Regards,
Showkath
-----------------------------------------------------
Our opinions do not really blossom into fruition until we have expressed them to someone else - Mark Twain
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