Click here to Skip to main content
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)176.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)

  Print Answers RSS
0 Sascha Lefévre 510
1 Sergey Alexandrovich Kryukov 300
2 Abhinav S 230
3 Maciej Los 185
4 Richard Deeming 105
0 Sergey Alexandrovich Kryukov 6,953
1 OriginalGriff 6,311
2 Maciej Los 2,732
3 Peter Leow 2,694
4 Abhinav S 2,652

Advertise | Privacy | Mobile
Web03 | 2.8.150414.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