Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USE [ArenaDB]
- GO
- /****** Object: StoredProcedure [dbo].[cust_CCIW_Update_profile_branch] Script Date: 10/27/2020 4:03:20 PM ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- -- Author: Ethan Jordan/Tony Visconti
- -- Date: 3/12/2020
- CREATE PROCEDURE [dbo].[cust_CCIW_Update_profile_branch]
- @Root INT,
- @Activate VARCHAR(1),
- @OrganizationID INT,
- @Update VARCHAR(1),
- @UpdateProfileBranchPageId INT
- AS
- BEGIN
- -- If they don't specify what to change or if to change anything show all profiles
- IF @Activate = ''
- BEGIN
- SELECT PT.Name,
- Profile_ID = '<a href="/default.aspx?page='+ CONVERT(VARCHAR(10), @UpdateProfileBranchPageId)
- +'&Root=' + CONVERT(VARCHAR(10), PT.profile_id) + '">' + CONVERT(VARCHAR(10), PT.profile_id) +
- '</a>',
- PT.Parent,
- PT.Root,
- PT.Root_ID,
- PT.Branch,
- [Current Status] = CASE WHEN PT.active = 1 THEN 'Active' ELSE 'Inactive' End
- FROM cust_CCIW_v_profile_tree PT
- WHERE Root_ID = @Root
- END;
- IF @Update = '1'
- BEGIN
- -- Create a temp list of profiles that need to be updated
- SELECT PT.Name,
- Profile_ID = '<a href="/default.aspx?page='+ CONVERT(VARCHAR(10), @UpdateProfileBranchPageId)
- +'&Root=' + CONVERT(VARCHAR(10), PT.profile_id) + '">' + CONVERT(VARCHAR(10), PT.profile_id) +
- '</a>',
- PT.Parent,
- PT.Root,
- PT.Root_ID,
- PT.Branch,
- [New Status] = CASE WHEN PT.active = 1 THEN 'Inactive' ELSE 'Active' End
- INTO #changes_temp
- FROM cust_CCIW_v_profile_tree PT
- WHERE Root_ID = @Root
- AND PT.active != @Activate;
- --Apply Updates
- UPDATE core_profile
- SET active = @Activate
- WHERE profile_id IN
- (
- SELECT profile_id
- FROM cust_CCIW_v_profile_tree
- WHERE Root_ID = @Root
- );
- -- Show what changed
- SELECT *
- FROM #changes_temp;
- END;
- ELSE
- BEGIN
- -- Show what will change
- SELECT PT.Name,
- Profile_ID = '<a href="/default.aspx?page='+ CONVERT(VARCHAR(10), @UpdateProfileBranchPageId)
- +'&Root=' + CONVERT(VARCHAR(10), PT.profile_id) + '">' + CONVERT(VARCHAR(10), PT.profile_id) +
- '</a>',
- PT.Parent,
- PT.Root,
- PT.Root_ID,
- PT.Branch,
- [Current Status] = CASE WHEN PT.active = 1 THEN 'Active' ELSE 'Inactive' End
- FROM cust_CCIW_v_profile_tree PT
- WHERE Root_ID = @Root
- AND PT.active != @Activate;
- END;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement