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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:19:36+00:00 2026-05-22T18:19:36+00:00

declare @all_customers as table( CustNum int ); /* –you can insert dummy data for

  • 0
declare @all_customers as table(   CustNum int ); 

/* --you can insert dummy data for testing purposes like so: 
 insert into @all_customers select 5, 1 union select 2, 1 --*/  

while (0 < (select count(*) from @all_customers))
begin  
declare @current_customer int = (select top 1 CustNum from @all_customers);   
declare @balance money = (select acct_balance from [crrsql].[dbo].[Customer] where CustNum = @current_customer);  
 update [crrsql].[dbo].[Customer] set Acct_balance = 0;   
 INSERT INTO [crrsql].[dbo].[AR_Transactions] (cashier_ID, CustNum, Balance) VALUES (100199, user, abs(@balance));    
 delete @all_customers where customernumber = @current_customer;
end 

Do i need to change the word table to the actual table name…or is that a keyword and if so how do i specify the table Customers
Basically i need to loop through [dbo].[Customer] table

  • 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-22T18:19:37+00:00Added an answer on May 22, 2026 at 6:19 pm
    declare @all_customers as table(   CustNum int ); 
    

    This is creating a table variable called @all_customers. Your code then goes on to iterate through this by taking the ID from top row from this temporary table, processing the customer with that ID, then removing the process ID from your list and repeating until the table is empty (i.e. all IDs have been processed). You can’t change the word table here, no. (This is essentially the same as using a cursor on the customers table I supposed but allowing you to modify the table underneath – I guess it isn’t quite as efficient, though.)

    If you want to process all you customers in this loop then you probably want to load their IDs into this table, e.g.

    declare @all_customers as table(   CustNum int ); 
    
    // Load customer IDs to process
    insert into @all_customers select CustNum from Customers; // where <condition>?
    
    while (0 < (select count(*) from @all_customers))
    

    That all said, I don’t see why you need the loop here. You could probably also just do:

    INSERT INTO [crrsql].[dbo].[AR_Transactions] (cashier_ID, CustNum, Balance)
    SELECT  100199, CustNum, abs(acct_balance)
      FROM  [crrsql].[dbo].[Customer];
    
    UPDATE [crrsql].[dbo].[Customer] set Acct_balance = 0;   
    

    to process all records in one go. (If you wanted to select a subset of customers you could do that with where clauses here too.)

    However this may not be appropriate if you have triggers on those tables that fire after each row update – there may be a deliberate reason they’re processed one at a time. If there’s no triggers, though, I can’t see a reason not to do the whole update at once. If it was intended as safety then as long as you wrap the whole thing in a transaction it doesn’t matter which way you do it – they’re equally as safe.

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

Sidebar

Related Questions

declare @customerID int set @customerID=1 ;with cteDates as ( select dateadd(hh, datediff(hh, 0, getdate()),
I am retrieving two or more tables data based on conditions, so I am
I have a stored procedure that returns all fields of an object. CREATE PROCEDURE
I have the following problem: As our app is going to be shown to
I tried to learn on my own, but soon started to realize that by
I've a not common problem to do a form validation. First let me explain
I have a query which works for every order except one. Here's the part
I am struggling with how to understand the correct usage of models. Currently i
I want to perform a hidden HTTP-GET request from MS-access, as simple as possible,
I am creating a project that uses a DLL. To build my project, I

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.