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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:49:47+00:00 2026-05-16T08:49:47+00:00

May I use variable to declaring cursors?? I want to creating dynamic cursor, how

  • 0

May I use variable to declaring cursors??

I want to creating dynamic cursor, how can i do this??

Regards

I have table:
CREATE TABLE [UsersUniTask] (
[id] uniqueidentifier CONSTRAINT [DF_UsersUniTask_id] DEFAULT newid() NOT NULL,
[userUniID] uniqueidentifier NOT NULL,
[taskID] int NOT NULL,
[time] datetime NOT NULL,
[doTask] int NOT NULL,
[priority] int NOT NULL,
CONSTRAINT [PK_UsersUniTask] PRIMARY KEY CLUSTERED ([id]),
CONSTRAINT [FK_UsersUniTask_UsersUni] FOREIGN KEY ([userUniID])
REFERENCES [UsersUni] ([id])
ON UPDATE NO ACTION
ON DELETE CASCADE
)
ON [PRIMARY]
GO

  • 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-16T08:49:48+00:00Added an answer on May 16, 2026 at 8:49 am

    Can you explain more about what you mean? If you are talking about declaring the cursor in a dynamic context as in the following example, then yes you can:

    DECLARE @i int -- variable input
    DECLARE @valuableData int
    
    SET @i = 1 -- value for that input, this could be set by a query
    
    DECLARE cursorFoo CURSOR FOR
        SELECT valuableData
        FROM myTable
        WHERE someParameter = @i
    
    OPEN cursorFoo 
    
    WHILE (1=1)
    BEGIN
        FETCH NEXT FROM cursorFoo 
             INTO @valuableData
    
        IF (@@FETCH_STATUS <> 0) BREAK
    
        SELECT @valuableData -- Do something with your data
    END
    
    CLOSE cursorFoo
    

    EDIT due to discussion in comments

    You should have two separate program loops here

    Loop 1:

    1. Webservice adds tasks to permanent
      table with information on priority.

    Loop 2:

    1. Server script queries permanent
      table for most important task
    2. Server script removes task from
      table and processes task (or hands
      that information off to a script
      that does the work
    3. Server script goes back to permanent
      table and looks for most important
      task

    SQL is meant to store data, not loop around and process it. The processing should be done with a server script. That script should get the data from the database. You start to have the concurrency issues you have having right now when SQL is writing and reading and looping through the same temporary table concurrently. You can do processing in SQL, but you should only use temp tables for data that is relevant only to that particular process.

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

Sidebar

Related Questions

I have a telerik grid with a dynamic data source (the grid may use
may i know how to use this getMicrophone with simpleFLVWriter to create flv with
Java doesn't allow you to use an variable that may not have been initialized
Possible Duplicate: What's an actual use of variable variables? OK, this question may look
When we want to modify some value in one object we may use two
I stumbled upon this code and I am curious as to what use may
This may sound stupid but how do I define a global variable in Go?
This may be something very easy but i can't seem to get this to
Is there a mechanism to have a conditional variable use multiple mutexes? I am
This may be a bit of a nooby question, I have been trying to

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.