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 help

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


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Tue Mar 11, 2008 10:35 am    Post subject: Query help Reply with quote

I am using following query:

Code:
SELECT                                     
DISTINCT A.CDE_HDQTR_CRW,                 
A.TXT_CRW_HDQTR,                           
A.CDE_HQ_PREFIX,                           
B.CDE_LOB,                                 
A.CDE_INACTV                               
FROM TJMSBCIT.TJMSCHDQ A,                 
     TJMSBCIT.TLABAL00 B                   
WHERE                                     
      A.CDE_INACTV NOT IN ('I')           
      AND A.CDE_HDQTR_CRW = B.CDE_HDQTR_CRW
WITH UR;


which fetches following results:

Code:
CDE_HDQTR_CRW   TXT_CRW_HDQTR                   CDE_HQ_PREFIX     CDE_LOB      CDE_INACTV
BARH22          22 LONDON SOUTH WEST DMA        200               AL           0         
BARH22          22 LONDON SOUTH WEST DMA        200               AL-DMA       0         
BARH33          33 LONDON S CENTRAL DMA         200               AL           0         
BARH33          33 LONDON S CENTRAL DMA         200               AL-DMA       0         
BARH42          42 LONDON S&SE DMA              200               AL           0         
BARH42          42 LONDON S&SE DMA              200               AL-DMA       0         
BILL11          11 SWINDON MCG NEW SERV METERS  500               MCG          0         
BILL11          11 SWINDON MCG NEW SERV METERS  500               MCG-NEWMTR   0         
BILL12          12 OXFORD MCG NEW SERV METERS   500               MCG          0         
BILL12          12 OXFORD MCG NEW SERV METERS   500               MCG-NEWMTR   0         
BILL13          13 WYCOMBE MCG NEW SERV METERS  500               MCG          0         
BILL13          13 WYCOMBE MCG NEW SERV METERS  500               MCG-NEWMTR   0       


Can somebody help me in modifying the query and getting the below result:

Code:
CDE_HDQTR_CRW TXT_CRW_HDQTR                     CDE_HQ_PREFIX  CDE_LOB    CDE_INACTV
BARH22        22 LONDON SOUTH WEST DMA          200            AL         0         
BARH33        33 LONDON S CENTRAL DMA           200            AL         0         
BARH42        42 LONDON S&SE DMA                200            AL         0         
BILL11        11 SWINDON MCG NEW SERV METERS    500            MCG        0         
BILL12        12 OXFORD MCG NEW SERV METERS     500            MCG        0     


Please help me.
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Tue Mar 11, 2008 11:39 am    Post subject: Reply with quote

What have you tried so far?
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: Tue Mar 11, 2008 12:06 pm    Post subject: Reply with quote

psmadhusudhan,

The only difference I see is the column CDE_LOB why dont u remove that from the distinct clause? If you need the column then try this

Code:

SELECT DISTINCT
       Z.CDE_HDQTR_CRW
      ,Z.TXT_CRW_HDQTR
      ,Z.CDE_HQ_PREFIX                           
      ,Z.CDE_LOB                                 
      ,Z.CDE_INACTV           
  FROM (SELECT A.CDE_HDQTR_CRW        AS CDE_HADQTR_CRW
              ,A.TXT_CRW_HDQTR        AS TXT_CRW_HDQTR
              ,A.CDE_HQ_PREFIX        AS CD_HQ_PREFIX 
              ,SUBSTR(B.CDE_LOB,1,3)  AS CDE_LOB
              ,A.CDE_INACTV           AS CDE_INACTV
          FROM TJMSBCIT.TJMSCHDQ A                 
              ,TJMSBCIT.TLABAL00 B                   
         WHERE A.CDE_INACTV NOT IN ('I')           
           AND A.CDE_HDQTR_CRW = B.CDE_HDQTR_CRW
          WITH UR) Z;


Hope this helps..
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Tue Mar 11, 2008 1:02 pm    Post subject: Reply with quote

A.CDE_HDQTR_CRW = B.CDE_HDQTR_CRW

You have multiple matchs on this field. You would need to narrow that down to a single match for each row in TJMSBCIT.TJMSCHDQ .
Back to top
View user's profile Send private message
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Wed Mar 12, 2008 2:58 am    Post subject: Reply with quote

Kolusu the query is giving following result:

Code:
CDE_HADQTR_CRW  TXT_CRW_HDQTR                   CD_HQ_PREFIX  CDE_LOB  CDE_INACT
---------+---------+---------+---------+---------+---------+---------+---------+
BARH22          22 LONDON SOUTH WEST DMA        200           AL       0       
BARH22          22 LONDON SOUTH WEST DMA        200           AL-      0       
BARH33          33 LONDON S CENTRAL DMA         200           AL       0       
BARH33          33 LONDON S CENTRAL DMA         200           AL-      0       
BARH42          42 LONDON S&SE DMA              200           AL       0       
BARH42          42 LONDON S&SE DMA              200           AL-      0       
BILL11          11 SWINDON MCG NEW SERV METERS  500           MCG      0       
BILL12          12 OXFORD MCG NEW SERV METERS   500           MCG      0     


I guess I need to explain the data. For the combination of CDE_HDQTR_CRW, TXT_CRW_HDQTR, CDE_HQ_PREFIX I need to have only one row in the output with all five fields. I can't use GROUPBY as I need specify CDE_LOB also in the clause, which will again give all rows for a particular combination of CDE_HDQTR_CRW, TXT_CRW_HDQTR, CDE_HQ_PREFIX. Any one value of CDE_LOB for this combination is sufficient. Is this possible to get such a output through a query.
_________________
Thanks
Madhu Sudhan
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