Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
SQL
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 FIND_IN_SET(s.id, REPLACE(a.RecordValue, ':', ',')) > 0 */
  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
/****** Object:  StoredProcedure [dbo].[UserPreferences_GetAllName]    Script Date: 10-10-2015 14:13:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
*   SSMA informational messages:
*   M2SS0003: The following SQL clause was ignored during conversion:
*   DEFINER = `root`@`localhost`.
*/

/*
*   SSMA informational messages:
*   M2SS0134: Conversion of following Comment(s) is not supported : ON FIND_IN_SET(s.id, REPLACE(a.RecordValue, ':', ',')) > 0 
*
*/

ALTER PROCEDURE [dbo].[UserPreferences_GetAllName]
AS 
   BEGIN

      SET  XACT_ABORT  ON

      SET  NOCOUNT  ON

      /* 
      *   SSMA error messages:
      *   M2SS0135: Unparsed SQL [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 FIND_IN_SET(s.id, REPLACE(a.RecordValue, ':', ',')) > 0 * / 
      *     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;] cannot be converted.

      */



   END
Posted
Updated 10-Oct-15 2:59am
v3
Comments
George Jonsson 10-Oct-15 5:14am    
At least make the effort to format the code properly.
Use the Improve question button, mark the code and select the language from the code menu.
CHill60 10-Oct-15 11:38am    
Why not just paste the thing into SSMS and deal with the errors one by one?
ZurdoDev 10-Oct-15 20:21pm    
As CHill says, the best way to do this is to paste it into Microsoft SQL and start fixing the errors.
Member 9528908 12-Oct-15 0:38am    
Thanx,

I have tried fix errors also, but some MySQL functions is not supporting into Sqlserver.

In MySQL we are using below functions,
-GROUP_CONCAT(DISTINCT c.Jobname)
-FIND_IN_SET(s.id, REPLACE(a.RecordValue, ':', ',')) > 0
but these two functions is not supporting in Sqlserver, instead of that which functions or logic we can use?
CHill60 12-Oct-15 8:29am    
If you google "sql equivalent of MySQL group_concat" and "sql equivalent of MySQL find_in_set" you should find some examples.
This looks really awful though - you might be better off giving some sample data and an example of the results you want - you'll probably get a better query

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900