**
**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 @j=@i
---set @i
select '@j'+''+'dec'+''+'31'
select distinct * into <destination> from <source> where <datecolumn><= '@j'+'-'+'dec'+'-'+'31'**
**
这就是我现在所做的,但问题是我需要每年从当前的数据中追加数据
答案 0 :(得分:0)
只需使用INSERT INTO
:
INSERT INTO <destination>
SELECT DISTINCT *
FROM <source>
WHERE <datecolumn> <= @j + '-dec-31'
请注意,您的原始语法是将@j
视为 literal 字符串,而不是将其替换为数字年份值。