Click here to Skip to main content
11,482,039 members (63,147 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL-Server-2008
Hello Friends,

I have a requirement that to show hierarchical records into the single record.
like i have table table1 with data:

emp_id old_status new status 
1      A          B
1      B          C
1      C          D
2      A          B
2      B          C
2      C          D
2      D          E

I want to show records in following manner:

emp_id status1 status2 status3 status4 status5
1      A       B       C       D
2      A       B       C       D    E

Thanks in advance
Rohan Lokhande
Posted 7-Apr-13 8:10am
Edited 7-Apr-13 8:11am
(no name)182.3K
Zoltán Zörgő at 7-Apr-13 13:14pm
You have a really important field missing: the order of these records.
Can there be more than 5 status values?
ThePhantomUpvoter at 7-Apr-13 13:15pm
You would use a PIVOT.
Maciej Los at 7-Apr-13 13:35pm
Which aggregate function (MAX, COUNT, SUM) you'll use?


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 7 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100