I need help with this SQL Server 2000 procedure. The problem is complicated because I am testing the procedure through Oracle SQL Developer.
I am starting a procedure to iterate a column with a new sequence of numbers in Varchar format for those who have null values.
But I keep getting the error, so a) Maybe I did the wrong approach. b) The syntax is invalid due to the version used. I am mainly an Oracle user.
The error I keep getting is: SQL Error: Incorrect syntax near the keyword 'End'. , which is not useful enough for correction. End refers to the most recent βEndβ in the procedure.
Any help would be greatly appreciated.
The procedure is performed here.
ALTER PROCEDURE [dbo].[OF_AUTOSEQUENCE] @JvarTable Varchar(250), @varColumn Varchar(250), @optIsString char(1), @optInterval int AS declare @topseed int, @stg_topseed varchar(100), @Sql_string nvarchar(4000), @myERROR int, @myRowCount int set @Sql_string = 'Declare MyCur CURSOR FOR select ' + @varColumn + ' from ' + @JvarTable + ' where ' + @varColumn + ' is null' Exec sp_executesql @Sql_string SET NOCOUNT ON Begin if @optIsString = 'T' Begin set @Sql_string = 'select top 1 ' + @varColumn + ' from ' + @JvarTable + ' order by convert(int, ' + @varColumn + ') desc' set @stg_topseed = @Sql_string set @topseed = convert(int, @stg_topseed) ENd else Begin set @Sql_string = 'select top 1 ' + @varColumn + ' from ' + @JvarTable + ' order by ' + @varColumn + ' desc' set @topseed = @Sql_string ENd -- SELECT @myERROR = @@ERROR, @myRowCOUNT = @@ROWCOUNT -- IF @myERROR != 0 GOTO HANDLE_ERROR open MyCur fetch next from MyCur WHILE @@FETCH_STATUS = 0 set @topseed = @topseed + @optInterval if @optIsString = 'T' begin set @Sql_string = 'update ' + @JvarTable + ' set ' + @varColumn + ' = cast((' + @topseed + ') as char) where current of ' + MyCur exec (@Sql_string) ENd else begin set @Sql_string = 'update ' + @JvarTable + ' set ' + @varColumn + ' = ' + @topseed + ' where current of ' + MyCur exec (@Sql_string) ENd fetch next from MyCur ENd -- SELECT @myERROR = @@ERROR, @myRowCOUNT = @@ROWCOUNT -- IF @myERROR != 0 GOTO HANDLE_ERROR --HANDLE_ERROR: --print @myERROR CLOSE MyCur DEALLOCATE MyCur End
sql-server stored-procedures syntax-error dynamic-sql sql-server-2000
Joshua
source share