Wednesday, May 15, 2013

Convert a SQL query result table to an HTML table for email

declare @body varchar(max)

set @body = cast( (
select td = dbtable + '' + cast( entities as varchar(30) ) + '' + cast( rows as varchar(30) )
from (
select dbtable = object_name( object_id ),
entities = count( distinct name ),
rows = count( * )
from sys.columns
group by object_name( object_id )
) as d
for xml path( 'tr' ), type ) as varchar(max) )

set @body = '' + ' ' + replace( replace( @body, '<', '<' ), '>', '>' ) + '
Database TableEntity CountTotal Rows
'

print @body

 <html>
   <head >
   </head>
   <body>
   <body>
 <html>

http://stackoverflow.com/questions/7070053/convert-a-sql-query-result-table-to-an-html-table-for-email

2 comments:

  1. this is awesome thank very helpfull

    ReplyDelete
  2. Asking questions are genuinely good thing if you are not understanding anything totally, however this post offers fastidious understanding even.

    ReplyDelete