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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Trigger a SQL Agent Job from Outside Mgmt Studio

Author  Topic 

benking9987
Posting Yak Master

124 Posts

Posted - 2010-06-10 : 17:50:19
Our backend database solution is SQL, but the front end that users interact with is MS Access. Works great BTW and we love it. However, I'm encountering an issue I'd like some input on.

I am creating a SQL Agent job that has about 18 steps using a combination of SSIS import/export and T-SQL statements. I can get all of the functionality to work just fine, but I want a way to trigger the job OUTSIDE of the SQL Management Studio. Since my users likely don't even know SQL exists, I don't want them to go into the Management Studio to fire off my job that processes the orders they need to look at. Does anyone know of a way to tell SQL to start the job based on something we can tell it from the outside? Maybe based on an insert function to a certain table?

Thanks in advance for your help.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-10 : 18:23:15
You can use sp_start_job. You can call it from a trigger based upon a DML statement (INSERT/UPDATE/DELETE).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

benking9987
Posting Yak Master

124 Posts

Posted - 2010-06-11 : 18:06:40
Sounds like this is what I want I'm thinking. So, I just build the Trigger to be called whenever I insert a new record onto a certain table, using the sp_start_job syntax? Am I understanding this correctly?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-11 : 18:36:32
You create an insert trigger and then call sp_start_job inside it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

benking9987
Posting Yak Master

124 Posts

Posted - 2010-06-14 : 18:53:40
Okay, so I'm a little embarrased, but I don't have any experience creating triggers, so the syntax is a little bit heinous for me. I am generally pretty good at adapting existing syntax to my needs, but have a hard time generating it out of nothing.

Basically, I want to run a SQL Server Agent job called "AZ_ImportOrders" every time there is an insert on table "AZ_Order_ImportTrigger". I know I need to create the trigger on that table, but I'm not sure where to start after:

CREATE TRIGGER.....

Sorry I'm so helpless. Any ideas?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-14 : 18:58:30
It's easiest to check BOL, the documentation for SQL Server, for syntax. But here you go:

CREATE TRIGGER someTriggerName
ON dbo.AZ_Order_ImportTrigger
FOR INSERT
AS
EXEC msdb.dbo.sp_start_job N'Some Job Name'
GO


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-14 : 21:18:41
You should be so easy playing pool....

Access...good lord....

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

benking9987
Posting Yak Master

124 Posts

Posted - 2010-06-16 : 12:08:34
Not sure I understand what you mean X002548, but I note the terrible feeling you have for MS Access. I know, its certainly not a fantastic solution, but its worked for us as our resources are limited both in terms of money to put into systems that do more than we need and in terms of development capability. For us, its a simple financial decision and so far it has paid dividends :)

Thank you Tkizer. I did look at BOL to begin with, but got more confused as they list pretty much all the syntax options out there. Triggers are certainly not an area that I have much experience in, but now I'll be better prepared for next time. Thanks again.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-16 : 12:46:41
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -