create PROCEDURE [dbo].[page]
    @startIndex int,
    @endIndex int,
@Count int out
AS
BEGIN
with temptbl as (
  SELECT ROW_NUMBER() OVER (ORDER BY productid desc)AS Row, 
  * from A
)
SELECT * FROM temptbl where Row between @startIndex and @endIndex 
select @Count =count(1) from a
END
godeclare @count int
exec page 1,2,@count out
print @count
/*
Row                  productid   salecount
-------------------- ----------- -----------
1                    125         3
2                    124         6(2 行受影响)4
*/

解决方案 »

  1.   

    不能用 select *  into #temp from ... 嗎?
      

  2.   


    create PROCEDURE [dbo].[page]
        @startIndex int,
        @endIndex int,
    @Count int out
    AS
    BEGIN
    with temptbl as (
      SELECT ROW_NUMBER() OVER (ORDER BY productid desc)AS Row, 
      * from A
    )
    SELECT * FROM temptbl where Row between @startIndex and @endIndex 
    select @Count =count(1) from a
    END
    godeclare @count int
    exec page 1,2,@count out
    print @count
    /*
    Row                  productid   salecount
    -------------------- ----------- -----------
    1                    125         3
    2                    124         6(2 行受影响)4
    */
      

  3.   


    USE [Water]
    GO
    /****** Object:  StoredProcedure [dbo].[Admin_SelectAll]    Script Date: 03/05/2009 12:35:00 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:        牛腩
    -- Create date: 20090302 14:31
    -- Description:    选择全部管理员记录
    -- =============================================
    ALTER PROCEDURE [dbo].[Admin_SelectAll]
        @startIndex int,
        @endIndex int
    AS
    BEGIN  SELECT ROW_NUMBER() OVER (ORDER BY id desc)AS Row, 
      ID,Name,Password,[Rank],CreateTime 
      into #temptbl 
      from AdminSELECT * FROM #temptbl where Row between @startIndex and @endIndex 
    --计算记录数
    declare @count int
    select @count=count(ID) from #temptbl
    drop table #temptbl
    return @count
    END