当前位置: 代码迷 >> Sql Server >> 分页存储过程(老是提醒0附近有语法异常)
  详细解决方案

分页存储过程(老是提醒0附近有语法异常)

热度:178   发布时间:2016-04-27 21:50:19.0
分页存储过程(老是提醒0附近有语法错误)
CREATE   procedure   GetProductsInCategoryintCount
                          ( @CategoryID   Int,
@pagesize   int,
                        @pageindex   int,
                        @docount   bit)
                        as
                        set   nocount   on
                        if(@docount=1)
                        select   count(ProductID)   from   Product   INNER   JOIN   ProductCategory   ON   Product.ProductID   =   ProductCategory.ProductID   where   productcategory.categoryid   =   @categoryid
                        else
                        begin
                        declare   @indextable   table(id   int   identity(1,1),nid   int)
                        declare   @PageLowerBound   int
                        declare   @PageUpperBound   int
                        set   @PageLowerBound=(@pageindex-1)[email protected]
                        set   @[email protected][email protected]
                        set   rowcount   @PageUpperBound
                        insert   into   @indextable(nid)   select   ProductID   from   Product   INNER   JOIN   ProductCategory   ON   Product.ProductID   =   ProductCategory.ProductID   where   productcategory.categoryid   =   @categoryid   order   by   ProductID   desc
                        select   O.*   from   Product   INNER   JOIN   ProductCategory   ON   Product.ProductID   =   ProductCategory.ProductID   O,@indextable   t   where   O.ProductID=t.nid
                        and   t.id> @PageLowerBound   and   t.id <[email protected]   order   by   t.id
                        end
                        set   nocount   off
                        GO

------解决方案--------------------
select O.* from Product INNER JOIN ProductCategory ON Product.ProductID = ProductCategory.ProductID O,@indextable t where O.ProductID=t.nid
and t.id> @PageLowerBound and t.id <[email protected] order by t.id
  相关解决方案