Can I transform XML to HTML in SQL Server?

I have a query that returns data as XML using the "for XML Clause" and then sends the result as the body of an email like so.

Declare @messBody as nvarchar(max)
Set @messBody = (Select * from tablehere where state = 1 for xml Auto)
Begin
  Exec msdb.dbo.ap_send_dbmail
      @profile_name = 'ProfileNameHere'
      @recipients = 'simon@example.com'
      @body = '@messBody
      @subject = 'SubjectHere'
End

It works and I get the email with the info I need but the body of the email is ugly XML. I would like to be able to transform it into pretty HTML. Can this be done in SQL Server?

Answers


I think you would need to use the CLR for that to do it by applying an XSLT transform.


One way would be to write a clr proc. Here is an article showing how: http://blogs.msdn.com/b/mrorke/archive/2005/06/28/433471.aspx


Need Your Help

Copy and pasting multiple items to the clipboard in IntelliJ IDEA

java keyboard-shortcuts intellij-idea

In IntelliJ IDEA, is it possible to have multiple items in your clipboard and choose which item to paste? What are the keyboard shortcuts?

NGINX redirect old https domain to new non-https

redirect ssl nginx

Yesterday I have changed my domain name hat was foobar.tk and it was running over https. For now, on my new domain foobar.eu I does not have ssl.