gpt4 book ai didi

sql-server - SQL 错误 : Incorrect syntax near the keyword 'End'

转载 作者:行者123 更新时间:2023-12-03 07:58:12 27 4
gpt4 key购买 nike

需要有关此 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

最佳答案

你缺少一个 begin紧跟在 WHILE 之后.你缩进就像你想要在 while 循环中的一个块(多个语句),甚至还有一个 endwhile ,但没有 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
...

关于sql-server - SQL 错误 : Incorrect syntax near the keyword 'End' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3628323/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com