Click here to monitor SSC
SQLServerCentral is supported by Redgate
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: 4170 | Views in the last 30 days: 14
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