declare @sql nvarchar(1000)
set @sql='select top '+@pagesize+' *,datediff(ms,'+cast(@testtime as varchar(30))+',getdate()) from #testtable where tid not in (select top '+cast(@pagesize * (@pageindex-1) as varchar(30))+' a.tid from #testtable a order by a.tid desc) order by tid desc'
exec (@sql)
---------------------------------------------------------------
我去掉datediff(ms,'+cast(@testtime as varchar(30))+',getdate())这句就没事,我想把查询用时统计出来,怎么写啊??注意查询用时可能会非常小!!
试试:
set @sql='select top '+@pagesize+' *,datediff(ms,'''+cast(@testtime as varchar(30))+''',getdate()) from #testtable where tid not in (select top '+cast(@pagesize * (@pageindex-1) as varchar(30))+' a.tid from #testtable a order by a.tid desc) order by tid desc'
select top 10 *,datediff(ms,01 6 2017 1:14PM,getdate()) from #testtable where tid not in (select top 89990 a.tid from #testtable a order by a.tid desc) order by tid desc