You can use the SQL Server Web Assistant to build a query, schedule a task, and generate an HTML file. You can put this functionality into your own code by using the sp_makewebtask stored procedure that generates the HTML file. This system stored procedure can be called by a Transact-SQL program. You can also call system stored procedures to run the task or drop the task.
For more information about these stored procedures, see What's New for Transact-SQL, later in this document.