将存储过程的输出数据插入表的列中

问题描述 投票:0回答:2

我在SQL Server中创建了一个存储过程。存储过程将同一表中的两列相减。如何将此存储过程数据插入表的列中?存储过程为:

ALTER PROCEDURE [dbo].[sp.StoreBilling]
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @Stock decimal(10,2)=0.00
    DECLARE @Spoilage decimal(10,2)=0.00

    SELECT A.Stock, A.Spoilage, A.Stock-A.Spoilage AS Inventory
    FROM dbo.Store AS A
END
sql sql-server
2个回答
0
投票

您可以创建表,也可以轻松使用现有表。

create table #BillingResult
(
    Stock int
    , Spoilage int
    , Inventory int
)

insert #BillingResult
exec [dbo].[sp.StoreBilling]

0
投票

在这样的新表中使用插入

alter PROCEDURE [dbo].[sp.StoreBilling]
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @Stock decimal(10,2)=0.00
    DECLARE @Spoilage decimal(10,2)=0.00    

    INSERT INTO NewTabeName(Stock, Spoilage, StockChange)
    SELECT A.Stock, A.Spoilage, A.Stock-A.Spoilage AS Inventory
    FROM dbo.Store AS A
END
© www.soinside.com 2019 - 2024. All rights reserved.