日期:2014-05-18 浏览次数:20645 次
EXEC('SELECT TOP '+@count+' * FROM [webcontent] WHERE enable=1 AND ID NOT IN(SELECT TOP '+@index+' ID FROM [webcontent] WHERE enable=1 ORDER BY [we_time] DESC) ORDER BY [we_time] DESC');
exec('SELECT TOP ' + cast(@count - @index as varchar) + ' ID FROM [webcontent] WHERE enable=1 ORDER BY [we_time] desc)' exec('SELECT TOP ' + cast(@count - @index as varchar) + ' ID FROM [webcontent] WHERE enable=1 ORDER BY [we_time])' exec('SELECT TOP ' + cast(@count - @index + 1 as varchar) + ' ID FROM [webcontent] WHERE enable=1 ORDER BY [we_time] desc)' exec('SELECT TOP ' + cast(@count - @index + 1 as varchar) + ' ID FROM [webcontent] WHERE enable=1 ORDER BY [we_time])'
------解决方案--------------------
--try: EXEC('select * from (SELECT TOP '+ltrim(@count)+' * FROM (select top '+ltrim(@index+@count)+' * from webcontent where enable=1 order by we_time desc)a order by we_time)a order by we_time desc') 另外给id,we_time字段加上索引。。
------解决方案--------------------
EXEC( 'select * from ( SELECT TOP '+ltrim(@count)+' * FROM (select top '+ltrim(@index+@count)+' * from webcontent where enable=1 order by we_time desc)a order by we_time)a order by we_time desc')
------解决方案--------------------
看你想要表达的意思应该是:查找一个记录集第M条到第N条记录。
你可以用你的语句结合,Exception关键字来实现
SELECT TOP M FROM TABLE WHERE .... ORDER BY ....
EXCEPTION
SELECT TOP N FROM TABLE WHERE .... ORDER BY ....