Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Returning multiple rows for one row in the table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
satishboddu

New User


Joined: 02 Aug 2011
Posts: 17
Location: India

PostPosted: Thu May 09, 2013 3:14 pm    Post subject: Returning multiple rows for one row in the table
Reply with quote

Hi ,

I have an Employee table which has employee records, I need to write a query which fetches employee records from the table based on certain criteria and also for each employee i need more than one output records in the result set of the query.

Example :

Code:
EMP_NO   EMP_Name   DOJ                 
101           Satish          01-05-2009
102           Srinu            04-20-2010

Output
Code:
EMP_NO   EMP_NAME       DOJ             WORK_SHIFT
101           Satish          01-05-2009          D
101           Satish          01-05-2009          N
102           Srinu            04-20-2010          D
102           Srinu            04-20-2010          N

How do we achieve this in SQL ?

Thanks in Advance

Satish ..
Back to top
View user's profile Send private message

Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1534
Location: Andromeda Galaxy

PostPosted: Thu May 09, 2013 3:26 pm    Post subject:
Reply with quote

Tr this

Code:
SELECT EMP_NO ,EMP_Name, DOJ,'D'
FROM <TABLENAME>
WHERE <CONDITION>
UNION ALL
SELECT EMP_NO ,EMP_Name, DOJ,'N'
FROM <TABLENAME>
WHERE <CONDITION>
;
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm
No new posts unload data from table with lob columns farhad_evan DB2 0 Sat Apr 22, 2017 1:32 pm
This topic is locked: you cannot edit posts or make replies. SDSF multiple spool datasets extracte... PJAlarcon CLIST & REXX 1 Fri Apr 21, 2017 10:50 pm
No new posts Validating file with multiple header/... mohitsaini DFSORT/ICETOOL 6 Thu Apr 13, 2017 1:53 am
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us