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 6055781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:18:11+00:00 2026-05-23T08:18:11+00:00

I am actually using a bad design with two cursors (I am aware of

  • 0

I am actually using a bad design with two cursors (I am aware of it but then the task was simple so I did not bother with the optimization). I am using a query like this:

DECLARE cursor1 CURSOR FAST_FORWARD FOR
SELECT DISTINCT name FROM #NameMeta;

OPEN cursor1;

FETCH NEXT FROM cursor1 INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN

  DECLARE cursor2 CURSOR FAST_FORWARD FOR
  SELECT DISTINCT place FROM #PlaceMeta;

  OPEN cursor2;

  FETCH NEXT FROM cursor2 INTO @place

  WHILE @@FETCH_STATUS = 0
  BEGIN

  ...
  ...
...
...

Until I actually clicked on the Execute button, I was pretty sure that this query is wrong and that it will bail out with an error. From what I see, there are two @@FETCH_STATUSs being used. So unless it is saving the status of the first @@FETCH_STATUS somewhere on a stack before opening a new cursor, this query should not work.

Can someone tell me how exactly this query works? My main question is about having multiple comparison checks with @@FETCH_STATUS. I manually hand verified some of the results but am not sure if this will fail for a corner case or the query is infact right and SQL Server is doing something else.

  • 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-23T08:18:11+00:00Added an answer on May 23, 2026 at 8:18 am

    @@FETCH_STATUS always returns the result from the most recent FETCH operation.

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

Sidebar

Related Questions

I'm new to Visual C# Studio (actually using the Express edition, but another developer
Actually I created a button using the cobogw widget library. But the button does
It's actually two part question regarding my simple page (that will be replaced some
Why using try catch is bad for application performance? I'm not saying about using
I am actually using h:selectOneRadio to display items, given to it from f:selectItems tag.
How do I do the following SQL in LINQ? I am actually using LINQ
Actually i am using the AsyncCalls library to execute an Query asynchronously in this
Has anyone using .net actually worked out how to successfully sign a signature to
I need to getting the client ip address using javascript.Actually,our connection provider ip is
I'm running a Hadoop job using Hive actually that is supposed to uniq lines

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.