我有一個SQL Server過程,我需要它轉換在MySQL工作。怎麼寫 「WITH CTE AS(SELECT ROW_NUMBER)OVER(ORDER(BY CASE」 在MySQL程序
下面是我的MySQL轉換的過程,我試過,但它不是完整的...
DELIMITER $$
DROP PROCEDURE IF EXISTS `SelectjqGridUsers` $$
CREATE PROCEDURE `SelectjqGridUsers` (IN PageIndex INT,IN SortColumnName VARCHAR(50),IN SortOrderBy VARCHAR(4) ,IN NumberOfRows INT ,OUT TotalRecords INT)
BEGIN
DECLARE StartRow INT;
DECLARE CTE VARCHAR(100);
SELECT TotalRecords = (SELECT COUNT(1) FROM Users);
SET StartRow = (PageIndex * NumberOfRows) + 1 ;
END $$
DELIMITER ;
這是我原來的SQL服務器程序:
CREATE PROC [SelectjqGridUsers]
@PageIndex INT ,
@SortColumnName VARCHAR(50) ,
@SortOrderBy VARCHAR(4) ,
@NumberOfRows INT ,
@TotalRecords INT OUTPUT
AS
BEGIN
SET NOCOUNT ON
SELECT @TotalRecords = (SELECT COUNT(1)
FROM [Users]
)
DECLARE @StartRow INT
SET @StartRow = (@PageIndex * @NumberOfRows) + 1 ;
WITH CTE
AS (SELECT ROW_NUMBER() OVER (ORDER BY CASE
WHEN @SortColumnName = 'UserID'
AND @SortOrderBy = 'asc'
THEN UserID
END ASC, CASE
WHEN @SortColumnName = 'UserID'
AND @SortOrderBy = 'desc'
THEN UserID
END DESC, CASE
WHEN @SortColumnName = 'UserName'
AND @SortOrderBy = 'asc'
THEN UserName
END ASC, CASE
WHEN @SortColumnName = 'UserName'
AND @SortOrderBy = 'desc'
THEN UserName
END DESC, CASE
WHEN @SortColumnName = 'FirstName'
AND @SortOrderBy = 'asc'
THEN FirstName
END ASC, CASE
WHEN @SortColumnName = 'FirstName'
AND @SortOrderBy = 'desc'
THEN FirstName
END DESC , CASE
WHEN @SortColumnName = 'MiddleName'
AND @SortOrderBy = 'asc'
THEN MiddleName
END ASC, CASE
WHEN @SortColumnName = 'MiddleName'
AND @SortOrderBy = 'desc'
THEN MiddleName
END DESC , CASE
WHEN @SortColumnName = 'LastName'
AND @SortOrderBy = 'asc'
THEN LastName
END ASC, CASE
WHEN @SortColumnName = 'LastName'
AND @SortOrderBy = 'desc'
THEN LastName
END DESC, CASE
WHEN @SortColumnName = 'EmailID'
AND @SortOrderBy = 'asc'
THEN EmailID
END ASC, CASE
WHEN @SortColumnName = 'EmailID'
AND @SortOrderBy = 'desc'
THEN EmailID
END DESC) AS RN ,
UserID ,
UserName ,
FirstName ,
MiddleName ,
LastName ,
EmailID
FROM [Users]
)
SELECT UserID ,
UserName ,
FirstName ,
LastName ,
MiddleName ,
EmailID
FROM CTE
WHERE RN BETWEEN @StartRow - @NumberOfRows
AND @StartRow - 1
SET NOCOUNT OFF
END
誰能幫我完成這個
嗨,寫代碼的請求是不是真的對堆棧溢出的話題。你能指出你遇到的具體問題嗎?你可以編輯你的問題。 –
@Pekka웃Thnx爲你的快速回復..如何寫「WITH CTE AS(SELECT ROW_NUMBER()OVER(ORDER BY CASE」in mysql procedure ... – vikas
你要花時間,並得到結果給我。 ..沒有人會這樣做 – Sahal