user5375600
user5375600

Reputation:

Cannot insert stored procedure results into db table

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

Answers (1)

Bert
Bert

Reputation: 82489

INSERT TotalBills (totalAmount) 
SELECT Sum(Amount)
FROM Bills 
WHERE id = @myID

Upvotes: 2

Related Questions