I need to create a temporary table and populate it with temporary values. The variables have values assigned from a python script. My code is as follows:
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
but this does not work. How can I populate a temporary table with variables?
You can just use insert into .... values
to make it.
INSERT INTO @temproj
(projectinfoid,
ordernumber,
periodofperformance,
popenddate,
popstartdate)
VALUES (@ProjectInfoID,
@OrderNumber,
@PeriodofPerformance,
@POPEndDate,
@PopStartDate)
Remove the parentheses around the select.
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
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.