Concantenate procedure and sql agent job creation

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

LVL 38
Jim P.Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
chapmandewConnect With a Mentor Commented:
easy change:

CREATE PROCEDURE [dbo].[CP_My_Proc]
AS
BEGIN
-- blah, blah
-- blah, blah
END
GO  --you were missing this.
USE [msdb]
GO
0
 
Jim P.Author Commented:
Dumb. I knew it was something simple.
0
All Courses

From novice to tech pro — start learning today.