我现在需要java从前台传参给sqlserver进行分页查询,请帮忙把分页sql写出,不要使用存储过程,sqlserver版本是2008,多谢!
如下是sql:
select con.iid id,con.iactname icname,ifl.iflowname ifname,con.istarttime isname,run.iacquiretime iqname,run.ilastoptime iltime,run.iowner iower,run.ilastop ilop from ieai_taskconstant con join ieai_taskruntime run on con.iid=run.iid join ieai_flowdef ifl on con.iflowid = ifl.iid order by con.istarttime desc
------解决方案--------------------
DECLARE @PageSize int=30,
@PageCount int=1,
@PageTotalCount INT,
@RowCount INT=0
SELECT
@RowCount=COUNT(1)
FROM
ieai_taskconstant con
JOIN ieai_taskruntime run ON con.iid=run.iid
JOIN ieai_flowdef ifl ON con.iflowid=ifl.iid
SELECT @PageTotalCount=CEILING(@RowCount*1.0/@PageSize),@PageCount=CASE WHEN @PageCount>=@PageTotalCount THEN @PageTotalCount ELSE @PageCount END
;WITH f AS
(
SELECT
rows=ROW_NUMBER()OVER(ORDER BY con.istarttime DESC),
con.iid AS id, con.iactname icname, ifl.iflowname ifname,
con.istarttime isname, run.iacquiretime iqname, run.ilastoptime iltime,
run.iowner iower, run.ilastop ilop
FROM
ieai_taskconstant con
JOIN
ieai_taskruntime run ON con.iid=run.iid
JOIN
ieai_flowdef ifl ON con.iflowid=ifl.iid
)
SELECT * FROM f WHERE rows BETWEEN (@PageCount-1)*@PageSize+1 AND @PageCount*@PageSize