Hi,
I currently have a stored procedure where I pass in the ID of a customer, and the stored procedure performs sum selects and updates a field in the same customer table. Like this;
But what if I want the stored procedure to automatically fill the 'BALANCE' column for ALL the patients. I'm not sure how to efficiently 'loop' through all the customers and track the @cusid variable.
Thanks
I currently have a stored procedure where I pass in the ID of a customer, and the stored procedure performs sum selects and updates a field in the same customer table. Like this;
Code:
CREATE PROCEDURE [dbo].[Balance]
(
@cusid Integer
)
AS
UPDATE CUSTOMERS
SET BALANCE =
(SELECT SUM(Amount)
FROM dbo.CUSTOMERS INNER JOIN
dbo.Transactions ON dbo.CUSTOMERS.ID = dbo.Transactions.[Customer ID]
WHERE (dbo.Transactions.[Customer ID] = @cusid))
WHERE ID = @cusid
GO
But what if I want the stored procedure to automatically fill the 'BALANCE' column for ALL the patients. I'm not sure how to efficiently 'loop' through all the customers and track the @cusid variable.
Thanks