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

  • Home
  • SEARCH
  • 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 4025390
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:50:27+00:00 2026-05-20T10:50:27+00:00

I have worked on SQL Server database. Now I have to work on a

  • 0

I have worked on SQL Server database. Now I have to work on a Sybase database (using a Squirrel client). This query is not working :

DECLARE @tableName VARCHAR(500);
DECLARE my_cursor CURSOR FOR

SELECT name
FROM   sysobjects
WHERE  type = 'U';
OPEN my_cursor;
FETCH NEXT FROM my_cursor INTO @tableName;
WHILE @@FETCH_STATUS = 0
    BEGIN
        //Do something here
        FETCH NEXT FROM my_cursor;
    END
CLOSE my_cursor;
DEALLOCATE CURSOR my_cursor; 

It gives an error – Incorrect syntax near the keyword 'FROM'.
SQLState: ZZZZZ
ErrorCode: 156
Error occured in:
FETCH NEXT FROM my_cursor INTO @table_Name

Now this works fine in a SQL Server database (after I change the last line to DEALLOCATE my_cursor). Can anybody tell me where I am going wrong?

  • 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-20T10:50:28+00:00Added an answer on May 20, 2026 at 10:50 am

    As Mitch points out the fetch syntax is:

    fetch cursor_name [into fetch_target_list]
    

    You also need to declare the cursor in a separate batch, this means you must put a “GO” after the declare statement. You will then find that your variable drops out of scope, so you’ll need to move that so that it’s after the “GO”.

    You also need to examine @@sqlstatus to see how successful the fetch was, rather than @@FETCH_STATUS which I think is MSSQL only.

    DECLARE my_cursor CURSOR FOR
      SELECT name
      FROM   sysobjects
      WHERE  type = 'U'
    go
    
    DECLARE @tableName VARCHAR(500)
    set nocount on
    OPEN my_cursor
    FETCH my_cursor INTO @tableName
    
    WHILE @@sqlstatus = 0
      BEGIN
          --Do something here
    
          FETCH my_cursor INTO @tableName
          print @tablename
      END
    
    CLOSE my_cursor
    DEALLOCATE CURSOR my_cursor
    

    And no semicolons needed at the end of lines in Sybase ASE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a legacy database which is a sql server db (2005, and 2008).
I'm using SQL Server 2008. I have a NVARCHAR(MAX) column called Title and i
I have an SQL Server database table created by deploying the following description in
I have a big SQL Server database I want to connect to and my
If any of you have worked with a cool tool for viewing/querying the SQL
I have worked on iPhone application but not aware of the formalities to submit
I've created a simple project with an SQL Server database with dozens of tables
I am upscaling an access 2003 database to SQL Server Express 2008. The tables
Let's say I've got a SQL Server database table with X (> 1,000,000) records
I have a large SQL script that creates my database (multiple tables, triggers, and

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.