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

If there is more than one office No related to a terminal


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

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Sat Jul 27, 2013 2:38 pm
Reply with quote

Hai

i have a table A that has three fields

terminal-id
product-id
office-number

terminal/product is primary key

How can I quickly find out if there is more than one office-number related to a terminal-id?

example

row 1
terminal A
product GTA
office 1245

row 2
terminal A
product SDG
office 1249

Here two offices are related to the same terminal

thnx
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Tue Jul 30, 2013 3:41 pm
Reply with quote

revdpoel,

Try this,
Code:
select terminalid, count(*)
from table
group by terminalid
having count(*) > 1


Thanks,
sushanth
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: Tue Jul 30, 2013 8:53 pm
Reply with quote

Hi Sushanth,

What if there were 2 rows with the same office# and multiple products?
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Wed Jul 31, 2013 10:12 am
Reply with quote

Hi D.sch.

This can do that,
Code:
SELECT officeno,
REPLACE(                                                         
REPLACE(                                                         
REPLACE(                                                         
CAST(XML2CLOB(XMLAGG(XMLELEMENT(NAME X , productid))) AS VARCHAR(200))
,'<X>','')                                                       
,'</X>',' ')                                                     
,'<X/>',' ')                                                     
FROM tbqual.tablename
GROUP BY officeno                                           
;                                                                 


revdpoel, this is for you

Code:
SELECT terminalid,
REPLACE(                                                         
REPLACE(                                                         
REPLACE(                                                         
CAST(XML2CLOB(XMLAGG(XMLELEMENT(NAME X , officeno))) AS VARCHAR(200))
,'<X>','')                                                       
,'</X>',' ')                                                     
,'<X/>',' ')                                                     
FROM tbqual.tablename
GROUP BY terminalid                                           
;                                                                 

(USED XML just to do row to column transformation)


Thanks,
Sushanth
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 Related to Unit Testing Testing & Performance 2
No new posts Strange MNOTE related to BMS using PI... CICS 0
No new posts Dynamically switching terminal model TSO/ISPF 9
This topic is locked: you cannot edit posts or make replies. Related to using a file in comparison JCL & VSAM 8
No new posts Ring the Bell on a 3270 terminal PL/I & Assembler 5
Search our Forums:

Back to Top