我需要将给定union所有连接查询的结果集存储到临时表
中DECLARE @no_of_days INT = 2
DECLARE @xxx DATETIME = '2009-11-04'
SELECT *
FROM source_price_curve
WHERE maturity_date >= DATEADD(DAY, -1 * @no_of_days, @xxx) AND maturity_date < @xxx
UNION ALL
SELECT *
FROM source_price_curve
WHERE maturity_date <= DATEADD(DAY, 1 * @no_of_days, @xxx) AND maturity_date > @xxx
答案 0 :(得分:0)
请尝试以下方法:
Insert Into #Temp
SELECT *
FROM source_price_curve
WHERE maturity_date >= DATEADD(DAY, -1 * @no_of_days, @xxx) AND maturity_date < @xxx
UNION ALL
SELECT *
FROM source_price_curve
WHERE maturity_date <= DATEADD(DAY, 1 * @no_of_days, @xxx) AND maturity_date > @xxx
答案 1 :(得分:0)
临时表插入必须在第一个选择中。
这是SqlFiddle上的演示。
DECLARE @no_of_days INT = 2
DECLARE @xxx DATETIME = '2009-11-04'
SELECT * into #Temp
FROM source_price_curve
WHERE maturity_date >= DATEADD(DAY, -1 * @no_of_days, @xxx) AND maturity_date < @xxx
UNION ALL
SELECT *
FROM source_price_curve
WHERE maturity_date <= DATEADD(DAY, 1 * @no_of_days, @xxx) AND maturity_date > @xxx