views:

80

answers:

4

Hi All,

I want to run a sql query on a specific schedule (weekly) and need to capture the output in an excel file as well.

Due to business restrictions we cannot use SQL server jobs and we cannot install Business Intelligence tools too.

Regards, RP

A: 

That pretty much rules out letting SQL Server do this for you. One alternative then is to create a Windows Service that contains a timer that fires on a schedule, that executes the query you need to do.

Randy Minder
A: 

set a Windows schedule task to run the osql Utility, which can fire off your SQL

KM
Thank you, I tried it but the OSQL was not able to place results in separate columns. Any ideas?
RP
produce a CSV file with .XLS file extension
KM
you should actually use `sqlcmd Utility` http://msdn.microsoft.com/en-us/library/ms162773.aspx, don't know what I was thinking, osql is going to be removed, doh!
KM
Create a linked server to the excel file. Use SQLCMD to put the data in to the correct columns.
G Mastros
here is a good link: http://mssqltips.com/tip.asp?tip=1202
KM
Thanks. It is useful and I hope will surely resolve my issue :)
RP
+2  A: 

Convince your company to stop being so obtuse -- you will end up writing a .NET app that acts as a service anyway -- its swings and roundabouts.

Hassan Syed
A: 

Use Windows Scheduled Tasks and a VBScript. The VBScript connects to the database to run the query and populates the Excel file with the results.

The following URL is an example.

http://digiassn.blogspot.com/2006/10/vbscript-populating-excel-file-from.html

Darryl Peterson