sql 批量数据查询分页
2011-04-02 09:51
316 查看
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[Proc_photolist]
(
@maximumRows int,
@startRowIndex int,
@usid int,
@ptzpid int,
@ptxcid int,
@ptdqid int,
@ptname varchar(50)
)
as
declare @strsql varchar(800)
declare @strwhere varchar(200)
if @ptname is null or @ptname=''
begin
set @strsql='select ptid,ptusid,ptzpid,ptdqid,ptxcid,ptname,ptsmpath,ptbgpath,ptaddtime,ptrq,pqjf,ptadstat,usid,uslinse,usnikname,ustname from (select ROW_NUMBER()Over(order by ptid desc) as rowId,* from View_Photo'
set @strwhere=''
if @usid<>0
set @strwhere=@strwhere+' and ptusid='+str(@usid)
if @ptxcid<>0
set @strwhere=@strwhere+' and ptxcid='+str(@ptxcid)
if @ptzpid<>0
set @strwhere=@strwhere+' and ptzpid='+str(@ptzpid)
if @ptdqid<>0
set @strwhere=@strwhere+' and ptdqid='+str(@ptdqid)
if @strwhere<>''
begin
set @strwhere=substring(@strwhere,5,len(@strwhere))
set @strsql=@strsql+' where '+@strwhere
end
set @strsql=@strsql+') as mytable where rowId between '+str(@startRowIndex+1)+' and '+str(@startRowIndex+@maximumRows)
execute(@strsql)
end
else
begin
set @strsql='select ptid,ptusid,ptzpid,ptdqid,ptxcid,ptname,ptsmpath,ptbgpath,ptaddtime,ptrq,pqjf,ptadstat,usid,uslinse,usnikname,ustname from (select ROW_NUMBER()Over(order by ptid desc) as rowId,* from View_Photo'
set @strwhere=''
if @usid<>0
set @strwhere=@strwhere+' and ptusid='+str(@usid)
if @ptxcid<>0
set @strwhere=@strwhere+' and ptxcid='+str(@ptxcid)
if @ptzpid<>0
set @strwhere=@strwhere+' and ptzpid='+str(@ptzpid)
if @ptdqid<>0
set @strwhere=@strwhere+' and ptdqid='+str(@ptdqid)
if @ptname <> ''
set @strwhere=@strwhere+' and ptname like ''%'+@ptname+'%'''
if @strwhere<>''
begin
set @strwhere=substring(@strwhere,5,len(@strwhere))
set @strsql=@strsql+' where '+@strwhere
end
set @strsql=@strsql+') as mytable where rowId between '+str(@startRowIndex+1)+' and '+str(@startRowIndex+@maximumRows)
execute(@strsql)
end
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[Proc_photolist]
(
@maximumRows int,
@startRowIndex int,
@usid int,
@ptzpid int,
@ptxcid int,
@ptdqid int,
@ptname varchar(50)
)
as
declare @strsql varchar(800)
declare @strwhere varchar(200)
if @ptname is null or @ptname=''
begin
set @strsql='select ptid,ptusid,ptzpid,ptdqid,ptxcid,ptname,ptsmpath,ptbgpath,ptaddtime,ptrq,pqjf,ptadstat,usid,uslinse,usnikname,ustname from (select ROW_NUMBER()Over(order by ptid desc) as rowId,* from View_Photo'
set @strwhere=''
if @usid<>0
set @strwhere=@strwhere+' and ptusid='+str(@usid)
if @ptxcid<>0
set @strwhere=@strwhere+' and ptxcid='+str(@ptxcid)
if @ptzpid<>0
set @strwhere=@strwhere+' and ptzpid='+str(@ptzpid)
if @ptdqid<>0
set @strwhere=@strwhere+' and ptdqid='+str(@ptdqid)
if @strwhere<>''
begin
set @strwhere=substring(@strwhere,5,len(@strwhere))
set @strsql=@strsql+' where '+@strwhere
end
set @strsql=@strsql+') as mytable where rowId between '+str(@startRowIndex+1)+' and '+str(@startRowIndex+@maximumRows)
execute(@strsql)
end
else
begin
set @strsql='select ptid,ptusid,ptzpid,ptdqid,ptxcid,ptname,ptsmpath,ptbgpath,ptaddtime,ptrq,pqjf,ptadstat,usid,uslinse,usnikname,ustname from (select ROW_NUMBER()Over(order by ptid desc) as rowId,* from View_Photo'
set @strwhere=''
if @usid<>0
set @strwhere=@strwhere+' and ptusid='+str(@usid)
if @ptxcid<>0
set @strwhere=@strwhere+' and ptxcid='+str(@ptxcid)
if @ptzpid<>0
set @strwhere=@strwhere+' and ptzpid='+str(@ptzpid)
if @ptdqid<>0
set @strwhere=@strwhere+' and ptdqid='+str(@ptdqid)
if @ptname <> ''
set @strwhere=@strwhere+' and ptname like ''%'+@ptname+'%'''
if @strwhere<>''
begin
set @strwhere=substring(@strwhere,5,len(@strwhere))
set @strsql=@strsql+' where '+@strwhere
end
set @strsql=@strsql+') as mytable where rowId between '+str(@startRowIndex+1)+' and '+str(@startRowIndex+@maximumRows)
execute(@strsql)
end
相关文章推荐
- SQL分页查询数据
- T-SQL 随机返回特定行数据和分页查询
- 关于SQL Server SQL语句查询分页数据的解决方案
- SQL大量数据查询分页存储过程
- SQL数据分页查询的方法
- MyBatis直接执行SQL查询及批量插入数据
- MyBatis直接执行SQL查询及批量插入数据
- 分页查询十万条以上数据的sql语句
- SQL中数据查询分页操作集中地
- MyBatis直接执行SQL查询及批量插入数据
- SQL 查询第N条数据 分页查询
- 使用一个T-SQL语句批量查询数据表占用空间及其行数
- java mysql分页查询大量数据,批量插入
- Hibernate 笔记 HQL查询(三) 分页,表连接,批量更新,引用SQL
- 使用一个T-SQL语句批量查询数据表占用空间及其行数
- 一条SQL查询单个数据和多个数据,并能在分页上显示
- MyBatis直接执行SQL查询及批量插入数据
- MVC中使用Linq To Sql进行数据查询及分页
- 使用一个T-SQL语句批量查询数据表占用空间及其行数
- 用@Query标注自定义查询语句用原生sql查询符合时间要求的数据与分页等功能