T-SQL does not have an easy way to transpose a row and a column. Of course, there is the PIVOT statement, but it doesn’t quite accomplish the task. In this article, Darko Martinovic shares another method using a SQLCLR stored prodedure.
SQLCLR is now considered a robust solution to the few niche requirements that can't be met by the built-in features of SQL Server. Amongst the legitimate reasons for avoiding SQLCLR, there is the fear of getting bogged down in code with special requirements that is difficult to debug. Darko takes a real example, extending the features of sp_send_dbmail, to demonstrate that there need be few terrors in SQLCLR.
This article shows a few techniques with SQLCLR to to transform a query result into HTML.