Home Forums SQL Server 2008 SQL Server Newbies PIVOT without aggregate function? RE: PIVOT without aggregate function?<!-- 864 --><!-- 864 --><!-- 864 --><!-- 864 --><!-- 864 -->

  • For anyone else needing a solution

    Got this to save as a SQL View thanks to Brian

    NOTE: the ColName fields must be the same data type.

    WITH Base AS

    (SELECT RowNum, TeamID, PersonID, CONVERT(varchar(100),CoachFN) AS CoachFN, CONVERT(varchar(100),CoachLN) AS CoachLN, CoachEmail

    FROM vTeamCoaches), norm AS

    (SELECT TeamID, ColName + CONVERT(varchar, RowNum) AS ColName, ColValue

    FROM Base

    UNPIVOT (ColValue FOR ColName IN ([CoachFN], [CoachLN],[CoachEmail])) AS pvt)

    SELECT *

    FROM norm

    PIVOT (MIN(ColValue) FOR ColName IN ([CoachFN1], [CoachLN1],[CoachEmail1],

    [CoachFN2], [CoachLN2],[CoachEmail2],

    [CoachFN3], [CoachLN3],[CoachEmail3],

    [CoachFN4], [CoachLN4],[CoachEmail4])) AS pvt