需要有关此SQL Server 2000过程的帮助。问题变得困难,因为我正在通过Oracle SQL Developer测试程序。
我正在运行程序,使用Varchar格式的新数字序列为具有空值的人重复列。
但我一直收到错误,所以a)我可能做错了方法b)由于使用的版本语法不正确。我主要是Oracle用户。
我一直收到错误:SQL Error: Incorrect syntax near the keyword 'End'.
没有足够的帮助解决它。 End
指的是过程中最后一个'结束'。
非常感谢任何帮助。
这是程序。
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
答案 0 :(得分:10)
你在begin
之后错过WHILE
。你在while循环中缩进就像你想要一个块(多个语句),甚至end
都有while
,但没有begin
。
制作:
...
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
...