简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM