How to run a stored procedure automatically every day - sql

How do I set up to run a stored procedure automatically every day in SQL Server 2008 R2?

Set up a SQL job http://msdn.microsoft.com/en-us/library/ms135739.aspx

You need to use the Job scheduler in the sql agent. Sql express doesn't include it so I just have a batch file run as a scheduled task to run it.
-James

Was discussed here:
Scheduled run of stored procedure on SQL server

Under SQL agent you need to go to the job scheduler and create a job that runs the stored proc. Once you have created the job you can create one or more schedules for the job. http://msdn.microsoft.com/en-us/library/ms135739.aspx

Related

Execute a stored procedure using SQL Server 2008 in SSIS

I want to execute a stored procedure using a SSIS package.
The output that generates from this stored procedure will also a script, so I want to execute that script output too. Can I schedule this SSIS package using SQL Server Agent?
You can execute a stored procedure in an Execute SQL Task in SSIS and send the output to a variable. You can then read the content of that variable in a second Execute SQL Task.
And yes, you can schedule the package to execute via a SQL Server Agent job. See this link for details.
Cheers -

Executing muliple Stored Procedures within a single SQL Server Agent Job

My SQL Server Agent job seems to execute the 1st SP cmd but not the second. Does anybody know how i get multiple commands into a single Server Agent job?
Use the GO command after executing each stored procedure.
Do you reference any FilteredViews in your sproc code? Then check this post and see if you can implement any of these solutions.

Can I close SSMS but leave a stored procedure running?

Is it possible to shut down ms sql server management studio while a stored procedure is running, without stopping the stored procedure?
If you mean an SP you are running within SSMS then no. Obviously closing your own SSMS won't affect SP's that are running from other users on the server.
You really can't, however you can create a SQL Agent job which will execute the stored proc do you need a result set returned to you or are you updating data?
If its an update I think you're fine just running it from the agent, if not, your next simplest way to return a long running stored proc's result set would to be create an SSIS package which outputs that result set to a csv, excel doc what ever is appropriate. This package can then also be executed by the SQL Agent.
Yes you can, but you will not be able to see the result of the SP if something is returned. Once the execution is given to server the server will execute the SP not the SSMS.

Is it possiple to run a stored procedure automatically without sql sever Agent?

Hello I am using MS SQL Management Studio express 2005 and I need to have a stored procedure to activate daily.
However I do not have SQL agent.
The Managemnet studio will not be opened daily so I can't use a startup script.
Anyone know how to do this without the Agent?
Thanks in advance.
you can use sqlcmd
http://msdn.microsoft.com/en-us/library/ms162773.aspx
then have that in a batch file and scheduled via windows scheduler
example below
sqlcmd -E -S localhost -q "select count(1) from databasename.dbo.tablename"
this will connect to sql on the local machine and perform a rowcount on the table in the database
Create a script that does the database call and use Scheduled Tasks to execute the script.
You can create a windows scheduled task to run the command line client osql.
It's not pretty, but you can create a stored procedure in master:
use master
go
CREATE PROCEDURE DoStuffDaily
AS
WHILE 1=1
BEGIN
WAITFOR TIME '00:05' --5 past midnight?
EXEC <yourdb>.<schema>.<proc>
END
go
Then just mark this stored proc as a startup procedure using sp_procoption, and restart SQL Server.

Any solutions to test SQL Agent Job immediately to ignore schedule

I am using SQL Server 2008 and I want to test the execution correctness of my SQL Server Agent job immediately to ignore the schedule. Any ideas?
thanks in advance,
George
In SSMS, under the "SQL Server Agent" node, open the "Jobs" subnode and find your job, right click on it and select "Start Job" - that'll start and run the job right away.
Marc
Create a stored procedure that encapsulates all the aspects of your job and then use that in SQL Agent. You can then just call the procedure from the command line to test it eg. exec dbo.MyProcedure #param1 = 'foo'
Change the schedule to have it run five minutes in the future.
Then get off the server so it runs in exactly the environment you want to test.