如何使用来自1个表和一些变量的数据创建临时表

时间:2015-08-28 15:02:45

标签: sql sql-server temp-tables

我正在尝试创建临时表。

SET @pstartDate = '01-01-2013'
SET @pendDate   = '31-12-2013'
SET @cstartDate = '01-01-2014'
SET @cendDate   = '31-12-2014'

CREATE TABLE #Temp
(
     pId int, 
     pname varchar, 
     ptype varchar, 
     pstartDate date, 
     pEndDate date, 
     cStartDate date, 
     cEndDate date
)

我将从产品表中获得pId,pname,ptype。

SELECT * 
INTO #Temp 
FROM product

INSERT INTO #TempTable (pStartDate, pEndDate, cStartDate, cEndDate) 
VALUES (@pStartDate, @pEndDate, @cStartDate, @EndDate)

我希望列pStartDate的值为'01 -01-2013',pEndDate为'31 -12-2013',cstartDate为'01 -01-2014',cEndDate为'12 -31-2014'为所有#Temp表格中的行

我正在尝试这种方式,但没有将值插入临时表。

1 个答案:

答案 0 :(得分:1)

你需要做这样的事情:

C:\[...]\Borland.Delphi.Targets(113,3): error : blub.pas(56) Error: E2029 ',' expected but identifier 'bla' found

您可以在select子句中组合列和变量,以获得所需的结果。