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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:35:17+00:00 2026-05-28T15:35:17+00:00

I have created an stored procedure in SQL Server 2008 and it contains the

  • 0

I have created an stored procedure in SQL Server 2008 and it contains the following code snippet:

WHILE (@COUNTER <= @COUNT_ROWSTOBEPROCESSED ) 
    BEGIN
        DECLARE @INFID AS INT =0;
        DECLARE @TPID AS INT =0;        
        SELECT @INFID = InfID FROM @TEMPTABLE WHERE @@ROWCOUNT = @COUNTER;
        print @INFID ;
            SET @COUNTER = @COUNTER + 1;        
    END

But it gives me following result:

(106 row(s) affected)
0
-26
0
0
0
0
0
0
0
0 all are zeros ....

I have already values in the temp table but it is not initialized into @INFID variable.

Why it is happening? I don’t understand…

Please help me, if anyone have a solution.

—-Comment—
yeap, I have seen into my code. But here I have already added counter increment in my code. but still i have same problem.
when i have run the below query inside the loop. i found that @@RowCount is always 1.

SELECT InfID,@ROWCOUNT FROM @TEMPTABLE WHERE @@ROWCOUNT = @COUNTER;

Can u tell me how to iterate each row of temptable using while loop or for loop in sql?

  • 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-28T15:35:18+00:00Added an answer on May 28, 2026 at 3:35 pm

    WHERE @@ROWCOUNT = @COUNTER is incorrect.

    @@ROWCOUNT returns the number of rows affected by the previous statement.

    It will only evaluate to true once. (When @COUNTER = 1) so the rest of the time no assignment is made to @INFID from the SELECT operation.

    What are you trying to do? My best guess is that you need to add an IDENTITY column to your table and reference that instead of @@ROWCOUNT or use a cursor.

    But if you explain your end goal we may be able to tell you a set based way of achieving whatever your goal is without RBAR processing.

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

Sidebar

Related Questions

I have created a little complex stored procedure on SQL Server 2008 R2 and
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
Using SQL Server 2008 I created a Stored Procedure called MyStoreProc and it runs
I have a stored procedure mentioned as below. I'm using SQL Server 2008 R2.
I have a SQL Server 2008 stored procedure (pseudocode below) that goes as follows:
I have a dynamic SQL statement I've created in a stored procedure. I need
I have a CLR stored procedure that references an assembly created in VS 2008
I'm writing a stored procedure in SQL Server 2008. It's a really long query
I have created a complex sql server 2008/coldfusion search page, that searches thru a
I have a SQL Server 2008 DBMS, and I have created an EDM (generated

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.