Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005
My database structure of attendance table is like this
ID   EmpName        Date             Status
1    Raj           1/12/2012             P
2    Rahul         1/12/2012             P
3    Raj           2/12/2012             P
4    Rahul         2/12/2012             P
5    Raj           3/12/2012             A
6    Rahul         3/12/2012             P
7    Raj           4/12/2012             A
8    Rahul         4/12/2012             P
 
And i want to customize the output in following format
  EmpName  1  2  3  4   
  Raj      P  P  A  A
  Rahul    P  P  P  P
 
So please help me on above issue
Posted 2-Jan-13 1:33am
Edited 2-Jan-13 1:56am
v2
Comments
@AmitGajjar at 2-Jan-13 6:37am
   
Pivot may work for you.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

PIVOT is an option. You have two approaches listed here: http://stackoverflow.com/questions/10976585/convert-rows-to-columns-using-pivot-in-mssql-when-columns-are-string-data-type[^]. Look for the accepted answer. And you will get a playground also to test it.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,569
1 Sergey Alexandrovich Kryukov 6,168
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
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