2014-07-08 40 views
-1
** 

**if (month(getdate())=01) and (day(getdate())=01) 
declare @i as datetime 
declare @j as datetime 
set @i = getdate() 
set @j=select year(@i)-3 
---set @[email protected] 
---set @i 
select '@j'+''+'dec'+''+'31' 
select distinct * into <destination> from <source> where <datecolumn><= '@j'+'-'+'dec'+'-'+'31'** 

**我需要大量的數據分成2點DB的當前和歷史

這是我已經高達現在完成了,但事情是我需要將數據從當前追加到歷史,每今年

+0

爲什麼不直接插入 SELECT DISTINCT * FROM WHERE ...'? –

回答

0

只需使用INSERT INTO:您原來的語法處理@j文字

INSERT INTO <destination> 
SELECT DISTINCT * 
FROM <source> 
WHERE <datecolumn> <= @j + '-dec-31' 

注而不是用數字年份值替換它。

相關問題