How to fetch rows into column in gridview with the help of sql server.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajeev patel
    New Member
    • Jun 2012
    • 1

    How to fetch rows into column in gridview with the help of sql server.

    How to fetch rows into column in gridview with the help of sql server.
    Id Date Attendance
    LAB01 2012-06-01 P
    FBD/SL/01/2012 2012-06-01 A
    FBD/SL/05/2012 2012-05-01 P
    LABOCP/121 2012-06-01 P
    LABOCP/123 2012-06-01 P

    LAB01 2012-06-02 P
    FBD/SL/01/2012 2012-06-02 A
    FBD/SL/05/2012 2012-05-02 P
    LABOCP/121 2012-06-02 P
    LABOCP/123 2012-06-02 P

    LAB01 2012-06-03 P
    FBD/SL/01/2012 2012-06-03 A
    FBD/SL/05/2012 2012-05-03 P
    LABOCP/121 2012-06-03 P
    LABOCP/123 2012-06-03 P

    LAB01 2012-06-05 P
    FBD/SL/01/2012 2012-06-05 A
    FBD/SL/05/2012 2012-05-05 P
    LABOCP/121 2012-06-05 P
    LABOCP/123 2012-06-05 P

    I would like to flip the rows to be columns so that this table looks like this in Gridview.

    Id 06-01 06-02 05-03 06-04 06-05 TP
    LAB01 P P P - P 4
    FBD/SL/01/2012 A P P - P 3
    FBD/SL/05/2012 P A P - P 3
    LABOCP/121 P P A - P 3
    LABOCP/123 P P P - A 3
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Depending on your version of SQL Server, you could use a pivot.

    Comment

    Working...