Query result display layout

  • Question, I have a query I select the data from it will return the data as such:

    ManagerName EmployeeName HoursWork

    John Mary 5

    John Kelly 55

    John Sue 80

    John Cathy 35

    Is there a statement I can use to have the same data display in a different format as such: (or do I have to write it using a Cursor)

    John Mary Kelly Sue Cathy

    5 55 80 35

  • kd11 (1/25/2015)


    Question, I have a query I select the data from it will return the data as such:

    ManagerName EmployeeName HoursWork

    John Mary 5

    John Kelly 55

    John Sue 80

    John Cathy 35

    Is there a statement I can use to have the same data display in a different format as such: (or do I have to write it using a Cursor)

    John Mary Kelly Sue Cathy

    5 55 80 35

    There is, indeed. Please see the following article for how.

    http://www.sqlservercentral.com/articles/Crosstab/65048/

    If you want a code for your specific example, please see the article at the first link under "Helpful Links" in my signature block below.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply