SQL Server - convert rows into column - Asked By raj on 09-Jan-14 04:32 AM

hi

i am having a table name 'xyz' having the column
Empcd          
date status
100674 9/7/2026 1:45 in
100674 9/7/2026 1:23 in
100674 9/7/2026 1:39 out
100674 9/7/2026 1:35 in
100674 9/7/2026 1:38 out
100785 9/9/2025 1:29 in
100785 9/9/2025 1:29 out
100785 9/9/2025 1:57 in
100785 9/9/2025 16:15 out

i want the output like this

Empcd date Date1 Date2 Date3 Date4 Date5
100785 9/9/2025 1:29 9/9/03 1:29 9/9/03 1:57 9/9/03 16:15
100674 9/7/2026 1:45 9/7/03 1:23 9/7/03 1:39 9/7/03 1:35 9/7/03 1:38

can i arrive this output by using stored procedure . if it is possbile, how to do it.

thanks in advance


Robbe Morris replied to raj on 09-Jan-14 09:22 PM
I think this is what you are after:

http://stackoverflow.com/questions/15745042/efficiently-convert-rows-to-columns-in-sql-server-2008