写出一条Sql语句 !好象比较有难度呢!这个是我写的,紧供参考,写错了的话,还请见谅!declare @i int, declare @temp_id1 int,@temp_id2 int declare my_cur cursor for select id from table order by id open my_cur fetch my_cur into @temp_id while(@@fetch_status=0) begin set @i =@i+1 if @i=31 --取到第31条记录 set @temp_id1=@temp_id --保存第31条记录的id if @i=40 set @temp_id2=@temp_id --保存第40条记录的id
fetch next my_cur into @temp_id end close my_cur deallocate my_curselect * from table where id between @temp_id1 and @temp_id2
SELECT TOP 40 * FROM EmployeeInfo WHERE EmployeeID NOT IN (SELECT TOP 31 EmployeeID FROM EmployeeInfo ORDER BY EmployeeID ASC) ORDER BY EmployeeID ASC这样可以不 ?
to 用一条SQL语句能写出来吗?可以,我上面给的存储是为了分页
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM T1 ORDER BY ID DESC) AS T2 ORDER BY ID DESC) AS T3 ORDER BY ID
http://blog.csdn.net/knight94/archive/2006/03/23/635885.aspx中的存储过程
declare @temp_id1 int,@temp_id2 int
declare my_cur cursor for
select id from table order by id
open my_cur
fetch my_cur into @temp_id
while(@@fetch_status=0)
begin
set @i =@i+1
if @i=31 --取到第31条记录
set @temp_id1=@temp_id --保存第31条记录的id
if @i=40
set @temp_id2=@temp_id --保存第40条记录的id
fetch next my_cur into @temp_id
end
close my_cur
deallocate my_curselect * from table where id between @temp_id1 and @temp_id2