日期:2014-05-17 浏览次数:20473 次
create proc [存储过程名]
(@p1 varchar(6000),
@p2 int,
@p3 int )
as
begin
set nocount on
declare @tsql varchar(6000)
select @tsql='with t as '
+'(select *, row_number() over(order by getdate()) ''rn'' '
+' from ('+@p1+') y) '
+'select top '+rtrim(@p2)+' * '
+'from t '
+'where rn>='+rtrim(@p2*@p3)
exec(@tsql)
end