Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Write Reports from SQL to Disk (Even HTML!)

By michael1047,

Ever need to write reports out to a folder? I have found that creating output files are SA-WEET! (and easy too) The sample script uses BCP to create an HTML file.

This process works well for reports that need to be generated nightly and take too long to run in real time.  Use an SMTP mail agent, and ALAS web based mail!

First open the script and change MYDATABASE to your database.

Second, add the script to your database then run the following:
  --Create the HTML file
  usp_writeSysObjectReport 'C:\sysobjects.html'
  --See the contents
  master..xp_cmdshell 'type c:\sysobjects.html'

  --Run this to clean up (uncomment)
  --master..xp_cmdshell 'erase c:\sysobjects.html'

You can use BCP to create HTML documents and/or HTML mail. Can create many reports fast! You could modify the output to push it to a web server.

Total article views: 4166 | Views in the last 30 days: 17
Related Articles

Report Script...

How to generate a completely report script...


Create Login Script

Error with Create Login Script


Generate Drop / Create Script for views, stored Procedures

This Script generates drop and create scripts for views or stored procedures.


Dynamically create drop user statistics scripts

Generate script to drop any unwanted user created statistics.


Script to create datestamp folder causing issue

Script to create datestamp folder causing issue


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones