Reputation:
I have a stored procedure that just sums a total value based on a customer ID that is passed in, which is all working fine as long as an id parameter is passed into it. Such as this....
CREATE TABLE TotalBills(
ID int identity(1,1) NOT NULL PRIMARY KEY,
totalAmount numeric(18,2)
)
GO
CREATE PROCEDURE customers
@myID nvarchar (50)
AS
SELECT sum(amount) from bills where id=@myID
//Cannot place amount into table TotalBills
Go
All I want to do is get the result inside the stored procedure and add it too my table all within the stored procedure. Having real difficulty doing this. Any ideas would be greatly appreciated.
Thank you.
Upvotes: 0
Views: 51
Reputation: 82489
INSERT TotalBills (totalAmount)
SELECT Sum(Amount)
FROM Bills
WHERE id = @myID
Upvotes: 2