ALTER PROCEDURE pr_tblAD_getAdsByParams(@pageNo int,@pageSize int,@name varchar(50),@classId int,@pageCount int output)ASdeclare @sqlTotal nvarchar(1000)declare @sqlGet nvarchar(1000)declare @recordCount intif(@name = '' and @classId=-1)begin-- 统计总记录数select @recordCount=count(*) from tblAD-- 返回当前页数据set @sqlGet = 'select top '+ str(@pageSize)+' * from tblAd where adId not in (select top '+str((@pageNo-1)*@pageSize)+ ' adid from tblAd)'endif(@name <> '' and @classId <> -1)begin-- 统计总记录数set @sqlTotal = N'select @recordCount=COUNT(*) from tblAd where name like ''%'+@name+'%'' and classId='+str(@classId)-- 返回当前页数据set @sqlGet = 'select top '+ str(@pageSize)+' * from tblAd where name like ''%'+@name+'%'' and classId='+str(@classId)+' and adId not in (select top '+str((@pageNo-1)*@pageSize)+ ' adid from tblAd where name like ''%'+@name+'%'' and classId='+str(@classId)+')'endif(@name='' and @classId<>-1)begin-- 统计总记录数set @sqlTotal = N'select @recordCount=COUNT(*) from tblAd where classId='+str(@classId)-- 返回当前页数据set @sqlGet = 'select top '+ str(@pageSize)+' * from tblAd where classId='+str(@classId)+' and adId not in (select top '+str((@pageNo-1)*@pageSize)+ ' adid from tblAd where name like ''%'+@name+'%'' and classId='+str(@classId)+')'endif(@name<>'' and @classId=-1)begin-- 统计总记录数set @sqlTotal = N'select @recordCount=COUNT(*) from tblAd where name like ''%'+@name+'%'''-- 返回当前页数据set @sqlGet = 'select top '+ str(@pageSize)+' * from tblAd where name like ''%'+@name+'%'' and adId not in (select top '+str((@pageNo-1)*@pageSize)+ ' adid from tblAd where name like ''%'+@name+'%'')'end-- 计算总页数if(@recordCount%@pageSize=0)set @pageCount=@recordCount/@pageSizeelseset @pageCount=@recordCount/@pageSize+1-- 返回当前页数据exec (@sqlGet)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。