SQL Server 存储过程将多个变量输入到临时表中



我需要创建一个临时表并用临时值填充它。变量具有从 python 脚本分配的值。我的代码如下:

ALTER PROCEDURE [dbo].[AddScrapedInfoBULK] 
(
-- Parameters for the SP, (each field in the all tables)
-- ProjectInfo Fields
@ProjectInfoID AS INT,
@OrderNumber AS NVARCHAR(255),
@PeriodofPerformance AS NVARCHAR(255),
@POPEndDate AS DATETIME,
@PopStartDate AS DATETIME
AS
BEGIN
SET NOCOUNT ON;
DECLARE @temproj TABLE (ProjectInfoID INT,
OrderNumber NVARCHAR(255),
PeriodofPerformance NVARCHAR(255),
POPEndDate DATETIME,
PopStartDate DATETIME)
INSERT INTO @temproj 
SELECT (@ProjectInfoID,
@OrderNumber,
@PeriodofPerformance,
@POPEndDate,
@PopStartDate)
END

但这行不通。如何使用变量填充临时表?

你可以用insert into .... values来制作它。

INSERT INTO @temproj 
(projectinfoid, 
ordernumber, 
periodofperformance, 
popenddate, 
popstartdate) 
VALUES      (@ProjectInfoID, 
@OrderNumber, 
@PeriodofPerformance, 
@POPEndDate, 
@PopStartDate) 

删除所选内容周围的括号。

DECLARE    @ProjectInfoID AS INT,
@OrderNumber AS NVARCHAR(255),
@PeriodofPerformance AS NVARCHAR(255),
@POPEndDate AS DATETIME,
@PopStartDate AS DATETIME
SET NOCOUNT ON;
DECLARE @temproj TABLE (ProjectInfoID INT,
OrderNumber NVARCHAR(255),
PeriodofPerformance NVARCHAR(255),
POPEndDate DATETIME,
PopStartDate DATETIME)
INSERT INTO @temproj 
SELECT @ProjectInfoID,
@OrderNumber,
@PeriodofPerformance,
@POPEndDate,
@PopStartDate

最新更新