Search This Blog

Thursday, February 7, 2013

Generate HTML reports from SQL Server

Do you know generating HTML reports via SQL Server is so simple using Web Assistant Procedures , please have a look at below steps to try out the same.

First Step to enable Web Assistant via sp_configure to use that feature.
sp_configure 'Web Assistant Procedures' ,1
reconfigure with override

Second step, this could be done via SQL Server or go to C Drive and create a folder named report for SQL Server to save the generated HTML report.

sp_configure 'xp_cmdshell' ,1
reconfigure with override

xp_cmdshell 'md C:\report'

This is the magic procedure which generates HTML report. And you could send absolutely any query and output is formatted in a neat manner in HTML page.

For example below we are sending Drive Free Space information i.e. procedure and next is getting list of databases and their status , each of it gets created as seperate tables in report.

Exec sp_makewebtask @outputfile    =    'C:\report\DB_REPORT.HTM',
                                     @query           =   
 'exec master..xp_fixeddrives
 select name,DATABASEPROPERTYEX(name,''Status'') AS Status from sysdatabases'

P.S:- Please note this feature is there in SQL 2005 and not in SQL 2000 nor in SQL 2008.