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
 

 

Column Ordering

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

New User


Joined: 24 May 2010
Posts: 86
Location: Pune

PostPosted: Wed Feb 24, 2016 4:53 pm    Post subject: Column Ordering
Reply with quote

I have a table with below data

Emp No Text Data Dept Num
1234 Wired duty 001
1234 8283838-10 002
1236 L/E 23-Jan 003
1238 Pipes fitted 001
1236 L/E 01-Feb 004
1234 L/E 01-Feb 004
1234 Testing 002

I want the query output as using ORDER BY

Emp No Text Data Dept Num
1234 L/E 01-Feb 004
1234 8283838-10 002
1234 Testing 002
1234 Wired duty 001
1236 L/E 23-Jan 003
1236 L/E 01-Feb 004
1238 Pipes fitted 001

That is Group of records with same Emp No grouped together. And with the same Emp No, Text Data records beginning with 'L/E' for the same EMp No to be grouped together and for Text Data other than beginning with 'L/E' should be grouped by Dept Num e.g.
1234 8283838-10 002
1234 Testing 002
Back to top
View user's profile Send private message

RahulG31

Active User


Joined: 20 Dec 2014
Posts: 331
Location: USA

PostPosted: Wed Feb 24, 2016 9:53 pm    Post subject: Reply to: Column Ordering
Reply with quote

What I can think of, is that you can include a case statement in your query like this:
Quote:
Select Emp_No, Text_Data,
CASE WHEN SUBSTR(Text_Data,1,3) = 'L/E'
THEN
' ' || Text_Data
ELSE
Text_Data
END AS SOMETHING
,Dept_Num
From MyTable
ORDER BY Emp_No, SOMETHING, Dept_Num

Since, you are prefixing Text_Data with a space only when 'L/E', the row containing 'L/E' will always be the first for each Emp_No record set.

*Note that you get 4 columns out of this query.

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

Global Moderator


Joined: 10 May 2007
Posts: 1713
Location: UK

PostPosted: Thu Feb 25, 2016 4:17 pm    Post subject:
Reply with quote

As you haven't used code tags to present your data nothing lines up. Why should reponders have to 'decode' your post in order to give an answer? Some may not even bother and it could be them that have the definitive answer for you. If you cannot be bothered, why should they?
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 SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Add system date inside of a PS file a... pramitdas DFSORT/ICETOOL 5 Sun Aug 28, 2016 12:06 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm
No new posts Query using SUBSTRING on a column of ... sasanka DB2 5 Mon Jul 04, 2016 1:01 pm


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