表结构如下:
id(int) updatetime(datetime)
1 2006-8-12 00:00:00
2 2006-5-12 00:00:00
3 2006-3-12 00:00:00
4 2006-10-12 00:00:00
存储过程部分代码:
crea proc GetNewAnnal
(
@scope int
)
begin
这里就麻烦各位前辈了
end
go
id(int) updatetime(datetime)
1 2006-8-12 00:00:00
2 2006-5-12 00:00:00
3 2006-3-12 00:00:00
4 2006-10-12 00:00:00
存储过程部分代码:
crea proc GetNewAnnal
(
@scope int
)
begin
这里就麻烦各位前辈了
end
go
insert #t select '2006-8-12 00:00:00'
union all select '2006-5-12 00:00:00'
union all select '2006-3-12 00:00:00'
union all select '2006-10-12 00:00:00'
GOCREATE PROCEDURE [GetNewAnnal]
@scope int
AS
begin
select * from #t
where updatetime>=convert(varchar,dateadd(day,-@scope,getdate()),120)
end
goexec GetNewAnnal 30drop table #t
drop proc GetNewAnnal
/*
id updatetime
----------- -----------------------
4 2006-10-12 00:00:00.000
*/
insert test
select 1, '2006-8-12 00:00:00' union
select 2, '2006-5-12 00:00:00' union
select 3, '2006-3-12 00:00:00' union
select 4, '2006-10-12 00:00:00'gocreate proc GetNewAnnal
(
@scope int
)
as
beginselect * from test where datediff(d,updatetime,getdate())<=@scopeend
godeclare @i int
set @i=30
exec GetNewAnnal @idrop table test
drop proc GetNewAnnal----------------------
id updatetime
----------- ------------------------------------------------------
4 2006-10-12 00:00:00.000