Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
malikjaved
Starting Member
21 Posts |
Posted - 2008-02-04 : 10:43:00
|
| HI Guys.Some how i create a varible into which i am abling to fetch a complete script of creating procedure or procedures . now i m hving problem how to run this script for varible, what i am doing isExec @SQL this @sql has complete script to that create procedure.i am receiving this error msgMsg 102, Level 15, State 1, Line 4Incorrect syntax near 'GO'.Msg 111, Level 15, State 1, Line 24'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.Msg 102, Level 15, State 1, Line 83Incorrect syntax near 'GO'.here is the value inside the @SQLIF EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tempdb]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[tempdb]GOCREATE PROCEDURE [dbo].[ModifiedProcedure]--@specific_name nvarchar(max),@DateFrom datetime,@DateTo datetime,@SQL varchar(max) OUTPUTAS--Declare variablesDECLARE @DropSQL nvarchar(max), @CreateSQL nvarchar(max)SET @SQL = ''--Get a list of procedures to drop and createSELECT'IF EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N''[dbo].[tempdb]'') AND type in (N''P'', N''PC''))DROP PROCEDURE [dbo].[tempdb]' AS [DropProcedure],cast(routine_definition as nvarchar(max)) as [CreateProcedure]INTO #ReplaceProceduresFROMINFORMATION_SCHEMA.ROUTINESWHEREroutine_type = 'PROCEDURE'AND LAST_ALTERED >= @DateFromAND LAST_ALTERED <= @DateTo--Create the ScriptDECLARE ProcedureScripingCursor CURSOR FOR SELECT DropProcedure, CreateProcedureFROM #ReplaceProceduresOPEN ProcedureScripingCursorFETCH NEXT FROM ProcedureScripingCursorINTO @DropSQL, @CreateSQLWHILE @@FETCH_STATUS = 0BEGIN SET @SQL = @SQL + @DropSQL SET @SQL = @SQL + CHAR(10) + 'GO' + CHAR(10) SET @SQL = @SQL + @CreateSQL SET @SQL = @SQL + CHAR(10) + 'GO' + CHAR(10) FETCH NEXT FROM ProcedureScripingCursor INTO @DropSQL, @CreateSQLENDGO |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-02-04 : 11:11:30
|
EXEC (@SQL) E 12°55'05.25"N 56°04'39.16" |
 |
|
|
malikjaved
Starting Member
21 Posts |
Posted - 2008-02-05 : 04:39:40
|
| Thanks for reply, but it's still not working,acutally the problem is that, you have complete script(drop/creating procedure) into a varible...i am hving problem.. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-05 : 08:23:33
|
| What does print @SQL result?MadhivananFailing to plan is Planning to fail |
 |
|
|
malikjaved
Starting Member
21 Posts |
Posted - 2008-02-05 : 09:48:38
|
| @sql is varible and it's just got the complete script of creating procedure,you can see the value in the first post...top of the page |
 |
|
|
|
|
|
|
|