I am trying to do the following: I need to execute a t-sql statement that contains the stored procedure creation script.
In reality this will have differnt stored procedure creation scripts which will be created in different databases depending upon certain criteria.
The example below is just for demo purposes. when i try to execute this in master it is showing me the following errors:
USE
MASTERGO
declare
@SQLString Nvarchar(1000)declare
@STR Nvarchar(1000)declare
@DBName nvarchar(100)SET
@DBName ='BTGenesisMDRockville'SET
@STR='create proc sptemp
@id int
as
select * from orders where id=@id
go
'
set
@SQLString='USE ' + @DBName + char(10) +'GO'set
@SQLString =@SQLString + @strEXEC
(@SQLString)
Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'GO'.
Msg 111, Level 15, State 1, Line 3
'CREATE PROCEDURE' must be the first statement in a query batch.
Msg 137, Level 15, State 2, Line 6
Must declare the variable '@id'.
Can anyone help me on this