This execution gives me the following error:
Msg 102, Level 15, State 1, Line 5 Incorrect syntax near 'go'. Msg 111, Level 15, State 1, Line 11 'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.
If I delete "GO", he gives me only the second.
Any hints that I'm missing?
declare @dbname varchar(500) set @dbname='master' Exec (' Use ' + @dbname + ' go create PROCEDURE [dbo].[krijo_database] @dbname nvarchar(2000), @Direktoria varchar(4000) AS BEGIN declare @stringu nvarchar(100) set @stringu = ''CREATE DATABASE '' + @dbname exec (@stringu) End ')
Answer
declare @dbname varchar(500) set @dbname='kontabel' Exec( 'Use ' + @dbname +' Exec ('' create PROCEDURE [dbo].[krijo_database] @dbname nvarchar(2000), @Direktoria varchar(4000) AS BEGIN declare @stringu nvarchar(100) set @stringu = ''''create DATABASE '''' + @dbname exec (@stringu) End '') ')
Actually, I tried it this way, and it worked, but I had to change the quotes. The actual procedure that I would like to use is more than 50,000 lines, and I can not go and manually change the quotes to everything.
Is there a better way?
source share