I have migrated one stored procedure but after migrated SP it is coming with commented lines because of some MySQL functions.
In MySQL i am using FIND_IN_SET() function but this function is not suitable in sqlserver that's why lines automatically showing commented.
i need to convert/Migrate MySQL stored procedure into sqlserver.
:-MySQL SP
DELIMITER $$
DROP PROCEDURE IF EXISTS `UserPreferences_GetAllName` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `UserPreferences_GetAllName`()
BEGIN
select d.UserId,d.CreatorId,
max(case when col = 'JOB' then d.RecordValue end) as JOB,
max(case when col = 'REMOTEACCESSTO' then d.RecordValue end) as REMOTEACCESSTO,
max(case when col = 'FLOWDIAGRAM' then d.RecordValue end) as FLOWDIAGRAM,
max(case when col = 'PAGESIZE' then d.RecordValue end) as PAGESIZE
from
(
select a.Id,a.CreatorId, a.UserId, 'JOB' col, case when (a.RecordValue ='All') then a.RecordValue
else GROUP_CONCAT(DISTINCT c.Jobname) end as RecordValue
from userpreference a left join jobs c
ON FIND_IN_SET(c.id, REPLACE(a.RecordValue, ':', ',')) > 0
where a.RecDescription='JOB' and a.IsActive=1
GROUP BY a.Id, a.UserId
union
select a.Id,a.CreatorId, a.UserId, 'REMOTEACCESSTO' col, case when (a.RecordValue ='All') then a.RecordValue
else GROUP_CONCAT(DISTINCT s.Name) end as RecordValue
from userpreference a left join server s
ON s.id IN (REPLACE(a.RecordValue, ':', ',')) > 0
where a.RecDescription='REMOTEACCESSTO' and a.IsActive=1
GROUP BY a.Id, a.UserId
union
SELECT a.Id,a.CreatorId, a.UserId, 'FLOWDIAGRAM' col, (case when (a.RecordValue ='1') then 'Visible'
else 'Not Visible'
end) as RecordValue
FROM userpreference a
where RecDescription='FLOW DIAGRAM' and a.IsActive=1
GROUP BY a.Id,a.Userid
union
SELECT a.Id,a.CreatorId, a.UserId, 'PAGESIZE' col, a.RecordValue
FROM userpreference a
where RecDescription='PAGE SIZE' and a.IsActive=1 GROUP BY a.id,a.UserId
) d Group by d.UserId;
END $$
DELIMITER ;
//After converted it is showing as below:
USE [opscentral]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[UserPreferences_GetAllName]
AS
BEGIN
SET XACT_ABORT ON
SET NOCOUNT ON
END