在线等,靠,这么简单的语句写不来,郁闷中
declare @pagesize varchar(10)-----显示每页数据的大小
declare @pageindex varchar(20)-----当前索引页
declare @testtime datetime -------建立测试时间
select @pagesize=10,@pageindex=9000,@testtime=getdate()
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())这句就没事,我想把查询用时统计出来,怎么写啊??注意查询用时可能会非常小!!
------解决方案--------------------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 '
------解决方案--------------------要用引号引起来
因为你传进来的是个时间字符串,是字符串一定要加单引号撒