列名或提供的值数与存储过程中的表定义不匹配

时间:2019-09-03 17:29:55

标签: sql-server stored-procedures

我正在尝试执行此存储过程,查询抛出错误:

  

列名或提供的值编号与表定义不匹配。

我想从此存储过程中得到的是所有列中的一行。

请帮助解决该错误。

ALTER PROCEDURE `uspx_MUL_Status`
   @OrderNumber VARCHAR(20),
   @SelectQty BIT,
   @SelectDate DATE,
   @oKey INT
AS 
BEGIN
    CREATE TABLE #TempStatus
    (
         OrderNum VARCHAR (20), 
         `QtéCom` SMALLINT, 
         `DateCom` DATE, 
         `QtéSelec` SMALLINT, 
         `DateSelec` DATE, 
         `QtéProd` SMALLINT, 
         DateProd DATE
    )

    INSERT INTO #TempStatus
        -- Quantité commandée--
        SELECT OrderNumber, SUM(`od.Quantity`), MAX(CreateDate)
        FROM OrderDetail `od`
        JOIN Orders o ON od.oKey =o.oKey
        WHERE OrderNumber = @OrderNumber
        GROUP BY CreateDate, OrderNumber

    -- Quantité sélectionnée--
    SET @SelectQty = 0
    SET @SelectDate = NULL

    SELECT @SelectQty = SUM(`sd.Quantity`), @SelectDate =  MAX(`ReleaseDate`)
    FROM ScheduleDetail `sd`
    JOIN Orders o ON o.oKey =`sd.oKey`
    JOIN Schedules s ON `sd.SchedID` = `s.SchedID` AND o.LocationID = s.LocationID
    WHERE o.oKey = @oKey
    GROUP BY ReleaseDate

    UPDATE #TempStatus
    SET `QtéSelec` = @SelectQty, `DateSelec` = @SelectDate

    -- Quantité produite--
    SET @SelectQty = 0
    SET @SelectDate = NULL

    SELECT
        @SelectQty = SUM(`od.CompleteQuantity`), 
        @SelectDate = MAX(`o.CompleteDate`)
    FROM OrderDetail `od`
    JOIN Orders o ON o.oKey = od.oKey
    WHERE o.oKey = @oKey
    GROUP BY CompleteDate

    UPDATE #TempStatus
    SET `QtéProd` = @SelectQty, `DateProd` = @SelectDate

    SELECT * FROM #TempStatus
END

EXEC `uspx_MUL_Status` @OrderNumber='TC19227', @SelectQty=0, @SelectDate=NULL, @oKey=42334

1 个答案:

答案 0 :(得分:1)

指定此行上的列:

INSERT INTO #TempStatus

赞:

INSERT INTO #TempStatus (Column1, Column2, Column3, etc)