Concantenate procedure and sql agent job creation

Posted on 2009-04-03
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?
-- blah, blah 
-- blah, blah 
USE [msdb]

Open in new window

Question by:Jim P.
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
LVL 60

Accepted Solution

chapmandew earned 250 total points
ID: 24060071
easy change:

-- blah, blah
-- blah, blah
GO  --you were missing this.
USE [msdb]
LVL 38

Author Comment

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

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why do I get extra rows when I do inner join? 12 43
Problem with SqlConnection 4 184
Passing value to a stored procedure 8 111
Help with SQL - TOP 10 by date and by group 13 42
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 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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…

749 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