Solved

Concantenate procedure and sql agent job creation

Posted on 2009-04-03
2
231 Views
Last Modified: 2012-05-06
I'm trying to script my SP creation and SQL Server agent job creation as one full length script.

I keep getting an error about the USE msdb for the job creation. It shouldn't looking at the USE statement as part of the SP creation.
--------------------------------------------------------------------
Msg 154, Level 15, State 1, Procedure CP_My_Proc, Line 125
a USE database statement is not allowed in a procedure, function or trigger.
--------------------------------------------------------------------

Any ideas?
CREATE PROCEDURE [dbo].[CP_My_Proc]
AS 
BEGIN
-- blah, blah 
-- blah, blah 
END
 
USE [msdb]
GO

Open in new window

0
Comment
Question by:Jim P.
2 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 250 total points
ID: 24060071
easy change:

CREATE PROCEDURE [dbo].[CP_My_Proc]
AS
BEGIN
-- blah, blah
-- blah, blah
END
GO  --you were missing this.
USE [msdb]
GO
0
 
LVL 38

Author Comment

by:Jim P.
ID: 24060160
Dumb. I knew it was something simple.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now