0

I use dynamic SQL to run a query:

    select @query = '
    SELECT C.LdcCode, ' + @cols + '
    FROM DailyTimesheetUnprocessedCount AS C
    LEFT OUTER JOIN #LdcSorting AS S
        ON C.LdcCode = S.LdcCode
    GROUP BY C.LdcCode, S.SortOrder
    ORDER BY ISNULL(S.SortOrder, 100)
    '

    execute(@query)

Is there a simple way to transpose the results of the query, so in my case LdcCodes would be column names, and what is now in @cols would be values in the first column?

Thanks.

David Shochet
  • 5,035
  • 11
  • 57
  • 105

0 Answers0