SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Auto-running Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dblynch90
Starting Member

USA
2 Posts

Posted - 05/13/2013 :  11:28:15  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1782 Posts

Posted - 05/13/2013 :  12:41:22  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 05/14/2013 :  00:32:15  Show Profile  Reply with Quote
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 MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

dblynch90
Starting Member

USA
2 Posts

Posted - 05/14/2013 :  10:02:28  Show Profile  Reply with Quote
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.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 05/15/2013 :  00:33:42  Show Profile  Reply with Quote
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 MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 05/15/2013 :  00:36:29  Show Profile  Reply with Quote
If you want to use t-sql alternative use bcp to export to excel with column names
see
http://beyondrelational.com/modules/2/blogs/70/posts/10846/export-to-excel-with-column-names.aspx

then add a sp_send_dbmail call to send this excel to email addresses

http://msdn.microsoft.com/en-IN/library/ms190307(v=sql.90).aspx

Wrap all the above inside a procedure and add a sql server agent job to automatically execute it as per a set schedule


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000