SQL 错误:关键字“End”附近的语法不正确

发布于 2024-09-17 18:56:18 字数 2611 浏览 6 评论 0原文

需要有关此 SQL Server 2000 过程的帮助。这个问题变得很困难,因为我正在通过 Oracle SQL Developer 测试过程。

我正在运行该过程,为那些具有空值的人使用 Varchar 格式的新数字序列迭代列。

但我不断收到错误,所以 a) 我可能采取了错误的方法 b) 由于使用的版本,语法不正确。我主要是 Oracle 用户。

我不断收到错误:SQL 错误:关键字“End”附近的语法不正确。 这对于解决该问题没有足够的帮助。 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

Need help with this SQL Server 2000 procedure. The problem is made difficult because I'm testing procedure via Oracle SQL Developer.

I'm running the procedure to iterate column with new sequence of numbers in Varchar format for those who have null values.

But I keep getting error, so a) I may have done a wrong approach b) syntax is incorrect due to version used. I'm primarily Oracle user.

Error I keep getting: SQL Error: Incorrect syntax near the keyword 'End'. which isn't helpful enough to fix it out. The End refers to the very last 'End' in the procedure.

Any help would be greatly appreciated.

Here's the Procedure.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姜生凉生 2024-09-24 18:56:18

您在 WHILE 之后缺少一个 begin。您可以缩进,就像您希望在 while 循环中使用一个块(多个语句)一样,甚至在 while 中有一个 end,但没有 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
...

you're missing a begin right after the WHILE. You indented like you want a block (multiple statements) in the while loop, and even have a end for the while, but no begin.

make 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
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文