Home Forums SQL Server 2008 T-SQL (SS2K8) Combining multiple rows into one row per employee RE: Combining multiple rows into one row per employee

  • Check the following article on Cross Tabs: http://www.sqlservercentral.com/articles/T-SQL/63681/

    WITH SampleData (PERSON, [DATA], [FIELD]) AS

    (

    SELECT 1234,'04/02/2014','Date'

    UNION ALL SELECT 1234,'123','Department'

    UNION ALL SELECT 1234,'80.0','Rate'

    )

    SELECT PERSON,

    MAX( CASE WHEN FIELD = 'Date' THEN DATA END) AS [Date],

    MAX( CASE WHEN FIELD = 'Department' THEN DATA END) AS Department,

    MAX( CASE WHEN FIELD = 'Rate' THEN DATA END) AS Rate

    FROM SampleData

    GROUP BY PERSON;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2