Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Concantenate procedure and sql agent job creation

Posted on 2009-04-03
2
Medium Priority
?
246 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 1000 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 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