Paging using Mysql Stored Proc

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WebNewbie
    New Member
    • Jul 2007
    • 15

    Paging using Mysql Stored Proc

    Hi, I am new to using mysql and there isn't any tutorials online on that shows how to create mysql stored procedure for paging purposes. Thus, I read tutorials on creating stored proc that were written for use with SQL Server. I just need to be shown how to convert the syntax to one that is compatible with MySQL. The following is the stored proc written for SQL Server, please show me how to convert to a MySQL compatible syntax. Thank you in advance for your help.

    [CODE=sql]CREATE PROCEDURE uspPaging
    @nStartValue INT,
    @nEndValue INT
    AS
    SET NOCOUNT ON

    DECLARE @tblTempData TABLE
    (
    NumID INT IDENTITY,
    ResID INT,
    ResType VARCHAR(50),
    ResDoc Blob

    )

    INSERT INTO @tblTempData
    (
    NumID,
    ResID,
    ResType,
    ResDoc,
    Firstn,
    Lastn
    )
    SELECT
    ResumeID,
    DocDate,
    Resumes,
    DocType,
    FirstName,
    LastName,
    DocDate
    FROM ResumeDB
    where Make = '" & LBoxProfessions .Items(i).Text & "'"

    SELECT EmployeeID,
    ResID,
    ResType,
    ResDoc,
    Firstn,
    Lastn
    FROM @tblTempData
    WHERE nID BETWEEN @nStartValue AND @nEndValue
    ORDER BY
    nID ASC[/CODE]
    Last edited by mwasif; Aug 4 '07, 11:57 AM. Reason: Added code tags
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, WebNewbie.

    Hate to burst your bubble, but that's why MySQL has a LIMIT clause:
    [code=mysql]
    SELECT
    `ResumeID`,
    `DocDate`,
    `Resumes`,
    `DocType`,
    `FirstName`,
    `LastName`,
    `DocDate`
    FROM
    `ResumeDB`
    WHERE
    `Make` = '...'
    LIMIT
    {START},{MAX}
    [/code]
    Where START is the number of rows you want to skip, and MAX is the maximum number of rows.

    For example, if each page had 20 results, you would use these LIMIT clauses:
    For page 1: LIMIT 0,20
    For page 2: LIMIT 20,20
    For page 3: LIMIT 40,20

    And so on.

    Comment

    Working...