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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:41:38+00:00 2026-06-01T21:41:38+00:00

CREATE TABLE #Tempcard ( Clubcard BIGINT NULL, DateTime DATETIME NULL ) WHILE 1=1 BEGIN

  • 0
    CREATE  TABLE  #Tempcard
          (
          Clubcard BIGINT NULL,
         DateTime DATETIME NULL 
          ) 


    WHILE 1=1
BEGIN
       WITH EventsTop1000 
       AS
       (
       SELECT  top 200 Clubcard,DateTime 
       FROM  Clubcard 
       WHERE(DATEDIFF(DAY ,Clubcard.DateTime ,getdate())>120))
       DELETE EventsTop200
        OUTPUT DELETED.* 
        INTO #Tempcard;
        IF (@@ROWCOUNT = 0)
        BREAK;
END

Here I am doing a Batch insertion. Once I insert the records to the #Tempcard table, I do not want to delete the data from the table Clubcard, but I need to fetch the next set of data from the Clubcard and again insert the data to #Tempcard.

If my records are 1020, I can see only 1000 records getting inserted, the rest 20 is not getting inserted.

Please let me know how to solve the issue.

  • 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-01T21:41:39+00:00Added an answer on June 1, 2026 at 9:41 pm

    If I understand correctly, you want to round number of rows to 200:

    insert into #Tempcard
    select top (select count(*) / 200 * 200 from Clubcard)
           Clubcard,
           DateTime 
    FROM  Clubcard 
    WHERE DATEDIFF(DAY, Clubcard.DateTime, getdate()) > 120
    

    You might consider using an order by to keep things consistent.

    If you are saying that you cannot insert all the records from Clubcard into #tempcard, I’ve tried it and it works correctly. #tempcard has 1020 records. I had to change CTE name though to EventsTop200.

    UPDATE: question clarified.

    If Clubcard can have nulls add real primary key to temporary table #Tempcard.
    To copy table in batch using t-sql code:

    CREATE  TABLE  #Tempcard
    (
        Clubcard BIGINT NOT NULL PRIMARY KEY,
        DateTime DATETIME NULL 
    )
    
    declare @StartClubCard bigint
    set @StartClubCard = 0
    
    WHILE 1 = 1
    BEGIN
       INSERT INTO #Tempcard
       SELECT TOP 200 Clubcard, DateTime
         FROM Clubcard 
        WHERE DATEDIFF(DAY, Clubcard.DateTime, getdate()) > 120
          AND Clubcard > @StartClubCard
        ORDER BY Clubcard
    
       IF @@ROWCOUNT = 0
          BREAK;
       select @StartClubCard = max (Clubcard)
         from #Tempcard
    END
    

    There might be problems. #Tempcard might miss records inserted after procedure copied their place in a batch, or might have records deleted after copying.

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

Sidebar

Related Questions

Create Table: CREATE TABLE `category` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255)
CREATE TABLE `social_activity_stream` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `social_actor_id` int(11) NOT NULL, `social_activity_id`
create table mainTable as select curr_Table.empID as empID, (currTable.ToTalDays-oldTable.ToTalDays) as DiffDays from currTable left
CREATE TABLE TR(STUDENT_ID int, SUBJECT_ID int, grade int); INSERT INTO tr SELECT * FROM
CREATE TABLE PERMISSIONS( ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(255) NOT NULL, UNIQUE(ID)
create table ImagenesUsuario { idImagen int primary key not null IDENTITY } This doesn't
create table snippet( id int not null auto_increment, primary key(id), idlanguage int not null,
CREATE TABLE Posts { id INT PRIMARY KEY AUTO_INCREMENT, title VARCHAR(200), url VARCHAR(200) }
CREATE TABLE Customer ( customerID int identity (500,20) CONSTRAINT . . dateCreated datetime DEFAULT
CREATE TABLE `db`.`Complete` ( `CompleteId` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,

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.