从MSSQL转换为MySQL

时间:2014-04-19 02:39:10

标签: mysql sql-server tsql

有人能将这个MSSQL表达式翻译成MySQL吗?

CREATE PROCEDURE `spGetEmployees`
@StartIndex int,
@MaximumRows int
as
BEGIN
    select EmployeeID,
           Name,
           Gender, 
           City,
           StartDate
      from (select row_number()
              over (order by EmployeeID)
                as RowNumber,
                   EmployeeID,
                   Name,
                   Gender,
                   City,
                   StartDate
              from tblEmployee) Employees
     where RowNumber >= @StartIndex
       and RowNumber < (@StartIndex + @MaximumRows);
END

tblEmployee是一个真实的表,而Employees是派生表。

1 个答案:

答案 0 :(得分:0)

mysql过程的一般语法是

CREATE PROCEDURE storedProcedureName( IN someString VarChar(150) )
BEGIN
  -- Sql queries goes here
END

在您的情况下,您的程序将类似于:

CREATE PROCEDURE spGetEmployees( IN StartIndex int, IN MaximumRows int)
BEGIN

select EmployeeID, Name, Gender, City, StartDate from
(select row_number() over (order by EmployeeID) as RowNumber, EmployeeID, Name,
    Gender, City, StartDate
from tblEmployee)  Employees
-- this part you may want to use limit or other mysql functions
--where RowNumber >= StartIndex and RowNumber < (StartIndex + MaximumRows);

END

如果您还需要,MySQL中临时表的基本语法如下:

CREATE TEMPORARY TABLE tableName(
emp_id VARCHAR(10),
 emp_Name VARCHAR(50),
emp_Code VARCHAR(30),
emp_Department VARCHAR(30)
);