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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:48:20+00:00 2026-05-24T23:48:20+00:00

I want to reference the nth row of the #temptable (at the second SQL

  • 0

I want to reference the nth row of the #temptable (at the second SQL comment is below). What expression will allow me to do so?

DECLARE @counter INT
SET @counter = 0
WHILE (@counter<count(#temptable))
--#temptable has one column and 0 or more rows
BEGIN
DECLARE @variab INT
EXEC @variab = get_next_ticket 3906, 'n', 1

INSERT INTO Student_Course_List
                SELECT  @student_id,
                -- nth result set row in #temptable, where n is @count+1
                @variab

SET @counter = @counter +1
END

Cursor (will this work?):

for record in (select id from #temptable) loop 
--For statements, use record.id 
end loop;
  • 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-24T23:48:20+00:00Added an answer on May 24, 2026 at 11:48 pm

    Instead of using a while loop (with a counter like you are doing) to iterate the table you should use a cursor

    Syntax would be:

    DECLARE @id int
    DECLARE c cursor for select id from #temptable
    begin
      open c
        fetch next from c into @id
        WHILE (@@FETCH_STATUS = 0)
        BEGIN
          --Do stuff here
          fetch next from c into @id
        END
      close c
      deallocate c
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this particular code sample I want to reference the second overloaded method (int
My data starts in C9 and I want to reference every 18th row. For
I want to reference a COM DLL in a .NET project, but I also
I am using the pimpl idiom and want to reference one of the methods
I want to hold reference to object so it doesn't get deleted in bind
Looking for good project methodologies.Anyone got some good reference links..want to share.
I want to get a reference to the Gmail Inbox button in Javascript? I
I want to store the current URL in a session variable to reference the
I want to know how we can get record count using reference cursor in
I want to hyperlink to a page within the Word 2007 Object Model Reference

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.