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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:53:55+00:00 2026-06-06T21:53:55+00:00

I have a cursor that I want to loop through a staging table, and

  • 0

I have a cursor that I want to loop through a staging table, and merge each record into another table.

I cant get this cursor just to loop through the records and return a count.

DECLARE @curCatalogID int
DECLARE @curNomenclature varchar(200)
DECLARE @curMainCategory varchar(200)
DECLARE @curSubCategory varchar(200)
DECLARE @curManufacturer varchar(200)
DECLARE @curModelNo varchar(200)
DECLARE @curPrice varchar(200)
DECLARE @curProductDesc varchar(2000)
DECLARE @curImage varchar(200)
DECLARE @curPDFName varchar(200)
DECLARE @curInventory varchar(200)
DECLARE @curBatchID int
DECLARE @curAuditID int

DECLARE @nCnt int
SET @nCnt = 0

DECLARE import_loop CURSOR FOR
SELECT * FROM tblCatalogStaging

OPEN import_loop
FETCH NEXT FROM import_loop 
INTO    @curCatalogID,
        @curNomenclature,
        @curMainCategory,
        @curSubCategory,
        @curManufacturer,
        @curModelNo,
        @curPrice,
        @curProductDesc,
        @curImage,
        @curPDFName,
        @curInventory,
        @curBatchID,
        @curAuditID

WHILE @@FETCH_STATUS = 0
BEGIN

SET @nCnt = @@ROWCOUNT;

        FETCH NEXT FROM import_loop 
        INTO    @curCatalogID,
        @curNomenclature,
        @curMainCategory,
        @curSubCategory,
        @curManufacturer,
        @curModelNo,
        @curPrice,
        @curProductDesc,
        @curImage,
        @curPDFName,
        @curInventory,
        @curBatchID,
        @curAuditID

END
CLOSE import_loop
DEALLOCATE import_loop

SELECT @nCnt

It should just return 1 value of 2036 ( number of rows in the staging table ) but im getting back like 2036 rows affected, 4072 rows affected, etc etc

  • 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-06-06T21:53:56+00:00Added an answer on June 6, 2026 at 9:53 pm

    I’m not so sure @@ROWCOUNT is meant to be used inside a CURSOR.

    You might have better luck with:

    DECLARE @nCnt INT
    SET @nCnt = 0
    ...
    SET @nCnt = @nCnt + 1;
    

    Note: A TRIGGER is probably the right place to be doing this validation on row insert/update. Unless you really only want the validation to happen sometimes. (Also, it’s SQL errors you’ll be raising, not exceptions)

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

Sidebar

Related Questions

How to get result in WITH table AS into CURSOR loop? I have previously
I have a cursor that is used to get some preliminary information for some
I currently have a database that within a loop checks a table if a
I have a function that displays a few divs running through a loop using
I have a cursor that queries a table like this CURSOR Cur IS SELECT
So I am using a cursor to loop through a bunch of records that
I have the following CSS that hides the mouse cursor for anything on the
I have a function in a package that returns a REF CURSOR to a
I have the following function that deletes the LaTeX command surrounding the current cursor
I have a custom QGraphicsItem, that (among other things) changed the cursor to an

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.