Advertisement
DataCCIW

Copy Event Steps and Events Settings

Jun 19th, 2019
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.75 KB | None | 0 0
  1. -- Identify Events with No Steps
  2. SELECT *
  3. FROM core_profile P
  4. LEFT JOIN [evnt_event_step] ON P.profile_id = evnt_event_step.profile_id
  5. WHERE
  6.     event_step_id is null
  7.     AND P.profile_type = 4
  8.  
  9. DECLARE @ProfileWithSteps INT = ;
  10. DECLARE @ProfileWithNoSteps INT = ;
  11. DECLARE @ProfileWithNoStepsName VARCHAR(100) = (SELECT P.profile_name from core_profile P where P.profile_id = @ProfileWithNoSteps)
  12.  
  13. -- Copy steps from @ProfileWithSteps into @ProfileWithNoSteps
  14. IF NOT EXISTS (SELECT TOP 1 S.event_step_id FROM evnt_event_step S WHERE S.profile_id = @ProfileWithNoSteps)
  15. BEGIN
  16.     INSERT INTO evnt_event_step
  17.     SELECT evnt_event_step.module_id,@ProfileWithNoSteps, evnt_event_step.step_order
  18.     FROM evnt_event_step
  19.     WHERE evnt_event_step.profile_id = @ProfileWithSteps
  20. END
  21. ELSE
  22. BEGIN
  23.  PRINT 'UNABLE TO COPY Steps to ' + @ProfileWithNoStepsName + ' already has steps'
  24. END
  25.  
  26. -- Copy step settings from @ProfileWithSteps into @ProfileWithNoSteps
  27. IF NOT EXISTS
  28.     (SELECT TOP 1 * FROM evnt_event_step S  
  29.         JOIN  evnt_event_step_setting SS on S.event_step_id = SS.event_step_id
  30.     WHERE S.profile_id = @ProfileWithNoSteps)
  31. BEGIN
  32.     INSERT INTO evnt_event_step_setting
  33.     SELECT (SELECT event_step_id from evnt_event_step where step_order = S.step_order AND profile_id = @ProfileWithNoSteps)
  34.         ,SS.name, SS.value,SS.type_id
  35.     FROM evnt_event_step S
  36.         JOIN  evnt_event_step_setting SS on S.event_step_id = SS.event_step_id
  37.     WHERE S.profile_id = @ProfileWithSteps
  38. END
  39. ELSE
  40. BEGIN
  41.     PRINT 'UNABLE TO COPY Step Settings to ' + @ProfileWithNoStepsName + ' already has step settings'
  42. END
  43.  
  44. -- Re-examine Events with No Steps
  45. SELECT *
  46. FROM core_profile P
  47.     LEFT JOIN [evnt_event_step] ON P.profile_id = evnt_event_step.profile_id
  48. WHERE
  49.     event_step_id is null
  50. AND P.profile_type = 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement