Groups | Blog | Home
all groups > sql server programming > december 2003 >

sql server programming : Creating a batch job which runs a stored proc


Vamsi
12/21/2003 11:56:12 PM
Hi,

I want to create a Batch job for Executing a Stored
Procedure and saving the output into an Excel Sheet,
Could someone advice me how to go about this.

I want to schedule a job in Windows. I cannot use DTS due
to some reasons. How can i go about saving the commands
in a batch file and scheduling this job??

Thanks for any help
John Bell
12/22/2003 10:21:58 AM
Hi

You may want to create a DTS job, there are plenty of examples of this sort
of things at http://www.sqldts.com/default.aspx?6

Alternatively, you may want to look at creating a file importable by Excel
such as a CSV file and use the BCP utility to create it.

mk:@MSITStore:C:\Program%20Files\Microsoft%20SQL%20Server\80\Tools\Books\cop
rompt.chm::/cp_bcp_61et.htm

John



[quoted text, click to view]

Vamsi
12/22/2003 5:19:19 PM
Hi,

Thanks. I think you have missed a few lines in my post.
The Site that you have suggested me completely deals with
DTS!!
I CANNOT use DTS due do some reasons,,, is there another
way???? like may be i can create a batch job, and
schedule it in windows!!!

If I can do it with a batch job,,, how do i go about
writing the sql stmts("Exec myStoredProcedure" & "Save
outputfile") in the batch file?? Can you pls advice.

Thanks,
Vamsi


[quoted text, click to view]
John Bell
12/28/2003 5:40:24 PM
Hi

There are plenty of examples of using BCP by searching google but this will
create a CSV file that will need converting into Excel format, but can be
loaded into Excel e.g:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=OlRefT56BHA.2252%40tkmsftngp04

Other alternative is to use the sp_OA* procedures e.g
http://www.sqlmag.com/Articles/Index.cfm?ArticleID=9153

John
[quoted text, click to view]

Peter Rand
12/28/2003 8:37:45 PM
Another option might be to program the extract directly in Excel, and then
batch the Excel file. For example, you could use the Data->Import External
Data->From a database, and specify the SQL as "exec sp_yourstoredprocedure",
returning the rows to Excel. Set up a macro to save the data to a new sheet
right before you exit Excel. Then batch the Excel file. I've used this type
of extract on a number of occations and it works just fine. DTS is
preferred, but since you can't use it, as noted below, you'd have to extract
to a flat CVS file and then import into Excel. And since you want to
schedule this in Windows (not a SQL Agent job), there's no requirement that
the Excel file be on the server...

Hope this helps,
Pete


[quoted text, click to view]

AddThis Social Bookmark Button