• This is not as simple as it seems. It sounds like you need a dynamic solution where the number of columns is unknown. Please refer to the 2 articles in my signature about cross tabs. The seconds one about dynamic cross tabs is exactly what you need for this sort of thing.

    Of course if this is a report, doing it in the front end is likely to perform faster than doing this in sql.

    Thank you Seane. Really useful articles.