SQL error: incorrect syntax next to the keyword "end"

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 /* Procedure OF_AUTOSEQUENCE Created by Joshua [Surname omitted] When 20100902 Purpose To fill up column with new sequence numbers Arguments varTable - Table name varColumn - Column name optIsString - Option: is it string or numeric, either use T(rue) or F(alse) optInterval - Steps in increment in building new sequence (Should be 1 (one)) Example script to begin procedure EXECUTE [dbo].[OF_AUTOSEQUENCE] 'dbo.EH_BrownBin', 'Match', 'T', 1 Any questions about this, please send email to [business email omitted] */ 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 
+7
sql-server stored-procedures syntax-error dynamic-sql sql-server-2000
source share
1 answer

you miss begin right after WHILE . You backtracked the way you want a block (multiple statements) in a while loop, and you even have an end for WHILE , but not begin .

do it:

 ... open MyCur fetch next from MyCur WHILE @@FETCH_STATUS = 0 begin --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<add this 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 ... 
+8
source share

All Articles