两个简单的分页SQL过程


create proc Page
(
@PageIndex int
)
as
declare @page int
declare @sql varchar(1000)
set @page=@PageIndex*5
set @sql=
'select top 5 Brand.BrandID,Brand.BrandName,Brand.HtmlUrl,Brand.TypeID,Brand.LogoUrl2,Brand_Type.BrandTypeName
from
Brand,Brand_Type
where
convert(int,substring(Brand.TypeID,2,1))=Brand_Type.BrandTypeId
and Brand.BrandID
in
(
select top '+str(@page)+' BrandID
from
Brand
order by UpdateDate Desc
)
and Brand.BrandID
not in
(
select top '+str(((@PageIndex-1)*5))+' BrandID
from
Brand

order by UpdateDate Desc
)
order by UpdateDate Desc'
exec(@sql)
  


create proc GetBrandBBS
@PageIndex int,
@BrandID int
as
declare @SQL Varchar(500)
begin
Set @SQL='select top 4 [ID],BrandID,Title,Content,UserName,Address,AddDate
from Brand_BBs 
where BrandID='+str(@BrandID)+'
and [ID]
in
(select top '+str(4*(@PageIndex))+' [ID] from Brand_BBs where BrandID='+str(@BrandID)+' order by [ID] desc)
and [ID]
not in
(select top '+ str(((@PageIndex-1)*4)) +' [ID]  from Brand_BBS where BrandID='+str(@BrandID)+' order By [ID] desc)
order by [ID] desc'
end

exec (@SQL)

posted on 2007-02-17 16:52  badyue  阅读(165)  评论(0编辑  收藏  举报

导航