Wednesday, February 15, 2012

custom pagination with mysql


CREATE  PROCEDURE `CustomPagination`(

IN in_CustomerId INT,
IN in_PageNumber INT,
IN in_maxRowsPerPage VARCHAR(100),
IN in_StartDate DATETIME,
IN in_EndDate DATETIME
)

BEGIN

       PREPARE statement FROM "select  CustomerId, CustomerTripId, TripDate, TollAmount
      
        from TripsTable where CustomerId = ? and TripDate between ? and ? order by CustomerTripId desc LIMIT ? , ?";
   

        SET @CustomerId := in_CustomerId;

        SET @StartDate := in_StartDate;
        SET @EndDate := in_EndDate;

        SET @startIndex := (in_PageNumber-1)*in_maxRowsPerPage;

        SET @maxRowsPerPage := in_maxRowsPerPage;

 

                EXECUTE statement USING @CustomerId, @StartDate,@EndDate, @startIndex,@maxRowsPerPage;

  

                DEALLOCATE PREPARE statement;

     

                END

No comments:

Post a Comment