My Category Table is
TABLE [Category](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Title] [nvarchar](512) NULL,
[Slug] [nvarchar](512) NULL,
[Details] [text] NULL,
[CategoryType] [int] NOT NULL,
[ParentId] [int] NULL,
[SortOrder] [int] NOT NULL
)
And My CTE Stored Procedure is
CREATE PROCEDURE [dbo].[sp_AllCategoryPath]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
;WITH CTE AS
(
SELECT Id, Title, Title as Path, ParentId, cast(Id as nvarchar(125)) as LinkPath,Slug
FROM Category
WHERE ParentId IS NULL
UNION ALL
SELECT t.[Id], t.[Title],
cast(cte.[Path] +'/'+ t.Title as nvarchar(512)),
t.ParentId,
cast(cte.[LinkPath] +'/'+ CONVERT(varchar(512), t.Id) as nvarchar(125)),
t.Slug
FROM Category t
INNER JOIN CTE ON t.ParentId = CTE.Id
)
SELECT cte.Id, cte.Title, cte.Path, cte.ParentId , c.Title as ParentName, LinkPath,cte.Slug
FROM CTE cte LEFT JOIN Category c ON cte.ParentId = c.Id
ORDER BY cte.Path
END
How can I convert this cte sp query to mysql sp compatible version ?
I want to change my sp to query because I am changing my asp.net core application db provider MSSQL to MySql server.
But I couldn't change cte sp to normal sp query.
My MySql Server Version 5.1.73