• I'm sorry, there's no way to get it with a PIVOT operation, because column names have to be explicitly defined.

    I'm just wondering why you need to get data that way: if it's just a presentation issue, you could reverse the logic of the loop that builds the output, running for columns vertically and for rows horizontally.

    The other option is to code the SELECT statement with a dynamic query, basically building the pivot string and then adding it to the base statement.

    -- Gianluca Sartori