How do I convert this MSSQL stored procedure to a mysql stored procedure?

Discussion in 'Databases' started by petervk, Nov 13, 2013.

  1. #1
    I'm starting out with stored procedures in mysql, but I'm used to mssql and have no idea how to add parameters and create mysql stored procedures. And yes, I checked tutorials on creating basic mysql stored procedures. Just not how to execute a string sql statement as can be seen in the example below.
    Please help!



    USE [tt]
    GO
    /****** Object: StoredProcedure [dbo].[_getNewsPagedSorted] Script Date: 6-11-2013 15:09:22 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    -- =============================================
    -- Author: <Author,,Name>
    -- Create date: <Create Date,,>
    -- Description: <Description,,>
    -- =============================================
    ALTER PROCEDURE [dbo].[_getNewsPagedSorted]
    @startRowIndex int
    ,@maximumRows int
    ,@sortExpression nvarchar(20)
    ,@Lang nvarchar(20)

    AS
    BEGIN
    SET NOCOUNT ON;

    if @sortExpression=''
    set @sortExpression='publishdate DESC'

    declare @sql nvarchar(max)

    set @SQL='SELECT * FROM (select ROW_NUMBER() OVER (ORDER BY '+@sortExpression+') as RowNum,
    * FROM news WHERE publishdate <=getdate() and lang=''' + @Lang + ''') as info
    WHERE RowNum > '+STR(@startRowIndex)+' AND RowNum <= ('+STR(@startRowIndex + @maximumRows)+') '

    EXEC sp_executesql @sql
     
    petervk, Nov 13, 2013 IP
  2. khodem

    khodem Well-Known Member

    Messages:
    206
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    120
    #2
    show the result you are looking for and some sample data... then only will be possible to help you out
     
    khodem, Dec 15, 2013 IP