Can anyone translate me this MSSQL expression to 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
is a real table and Employees is derived table.
The general syntax for mysql procedures is
CREATE PROCEDURE storedProcedureName( IN someString VarChar(150) )
BEGIN
-- Sql queries goes here
END
IN your case, your procedure would be something like:
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
If you also need, the basic syntax of temporary tables in MySQL is something like:
CREATE TEMPORARY TABLE tableName(
emp_id VARCHAR(10),
emp_Name VARCHAR(50),
emp_Code VARCHAR(30),
emp_Department VARCHAR(30)
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.