Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1040481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:13:45+00:00 2026-05-16T15:13:45+00:00

Need help with this SQL Server 2000 procedure. The problem is made difficult because

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:13:46+00:00Added an answer on May 16, 2026 at 3:13 pm

    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
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help in explaining this behavior in SQL Server 2008. I have
I need help on T-SQL. I have a stored procedure in my SQL Server
I'm not good at t-sql, so I need help. I have this code I
Okay, I need help. I'm usually pretty good at SQL queries but this one
I need help with SQL Server Table Column. I´m trying to rename Column Name,
I need some help with a SQL query for SQL Server 2005. Here is
I need your help :) I have a table in a database (SQL Server
I need help inserting xml files into SQL Server 2008. I have the following
I need a little help figuring this out because I'm new to stored procedures.
I'm a c# SQL Server developer new to Oracle programming . The code below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.