SQL 错误:关键字“End”附近的语法不正确
需要有关此 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在
WHILE
之后缺少一个begin
。您可以缩进,就像您希望在 while 循环中使用一个块(多个语句)一样,甚至在while
中有一个end
,但没有begin
。做到:
you're missing a
begin
right after theWHILE
. You indented like you want a block (multiple statements) in the while loop, and even have aend
for thewhile
, but nobegin
.make it: