Solved

Concantenate procedure and sql agent job creation

Posted on 2009-04-03
2
228 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

19 Experts available now in Live!

Get 1:1 Help Now