Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
dblynch90
Starting Member
2 Posts |
Posted - 2013-05-13 : 11:28:15
|
So I am not 100% sure if I am posting in the right section but I am looking for some help with something.I have a query that I run every day, that I would like to be a bit more automated. It is a simple select statement that queries a table for values. I would like to make either a batch file, or C++ program that I can setup as a scheduled task to run this query every morning. What is the easiest way in running a select statement from a batch file or C++ program? |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2013-05-13 : 12:41:22
|
If you want to run your script from the application level there is a application named Task Scheduler. It ships with the operating system. Alternately, you could use SQL Server Agent to create and schedule a Task. The task would consist of your script.=================================================There are two kinds of light -- the glow that illuminates, and the glare that obscures. -James Thurber |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-14 : 00:32:15
|
sorry but where do you want to capture results? Just running a select statement automated doesnt make any sense to me. Is attempt to show some kind of report for users?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
dblynch90
Starting Member
2 Posts |
Posted - 2013-05-14 : 10:02:28
|
Basically documents are scanned and electronically fed into a database. Every day I need to run a report on how many documents were entered into the system the day before, save it as an excel sheet, and email it off to a customer. I am trying to make it so these reports run and save automatically, so all I need to do is email them off. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-15 : 00:33:42
|
ok. in that case much better way is to create a report in reporting services. It will have a datasource defined which will connect to your database table and will have a dataset which will run query and populate the data. Inside report you include the columns you want and deploy it in report server. Then in server set a subscription for report by specifing email as delivery option and give required email address and format as Execl. Then it will get rendered in excel format to desired distribution list automatically.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-15 : 00:36:29
|
If you want to use t-sql alternative use bcp to export to excel with column namesseehttp://beyondrelational.com/modules/2/blogs/70/posts/10846/export-to-excel-with-column-names.aspxthen add a sp_send_dbmail call to send this excel to email addresseshttp://msdn.microsoft.com/en-IN/library/ms190307(v=sql.90).aspxWrap all the above inside a procedure and add a sql server agent job to automatically execute it as per a set schedule------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|