Author: alto123 | Posted on: 9/14/2009 2:48:23 AM | Views : 555

I am writing a procedure for selecting a table, I want to get the count of the rows along with the table.

My proc:
ALTER PROC USP_SELECT_PRODUCTS_BY_PAGESIZE
(
@STARTROWINDEX INT,
@PAGESIZE INT,
@TOTALCOUNT INT OUTPUT
)
AS
SET @STARTROWINDEX = @STARTROWINDEX + 1;

WITH PRODUCTLIST AS (
SELECT *, ROW_NUMBER() OVER (ORDER BY ProdId ASC) as ROWNUM FROM [TblProduct]
)
SELECT * FROM PRODUCTLIST WHERE ROWNUM BETWEEN @STARTROWINDEX AND (@STARTROWINDEX + @PAGESIZE) - 1
ORDER BY PRODID ASC

SET @TOTALCOUNT = (SELECT COUNT(PRODID) FROM [TblProduct])
this is front end code:
SqlParameter param = new SqlParameter("@TOTALCOUNT", DbType.Int32);
          &nb ...

Go to the complete details ...