Solved

Concantenate procedure and sql agent job creation

Posted on 2009-04-03
2
243 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.
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this article I will describe the Copy Database Wizard 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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

623 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