Advertisement
DataCCIW

cust_CCIW_funct_profile_path

Jul 8th, 2019
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.88 KB | None | 0 0
  1. USE [ArenaDB]
  2. GO
  3.  
  4. /****** Object:  UserDefinedFunction [dbo].[cust_CCIW_funct_profile_path]    Script Date: 7/8/2019 3:00:12 PM ******/
  5. SET ANSI_NULLS ON
  6. GO
  7.  
  8. SET QUOTED_IDENTIFIER ON
  9. GO
  10.  
  11. CREATE function [dbo].[cust_CCIW_funct_profile_path] (
  12. @ProfileID int
  13. )
  14.     RETURNS varchar(2000)
  15.  
  16. AS
  17.  
  18. BEGIN
  19.  
  20.  
  21.     DECLARE @ParentProfileID int
  22.     DECLARE @ProfilePath varchar(2000)
  23.  
  24.     SET @ParentProfileID = @ProfileID
  25.     SET @ProfilePath = ''
  26.  
  27.     WHILE @ParentProfileID IS NOT NULL AND @ParentProfileID <> -1
  28.     BEGIN
  29.         IF @ProfilePath <> '' SET @ProfilePath = ' \ ' + @ProfilePath
  30.         SET @ProfilePath = ISNULL(
  31.             (SELECT profile_name  
  32.             FROM core_profile
  33.             WHERE profile_id = @ParentProfileID), '[Deleted Profile]' ) + @ProfilePath
  34.        
  35.         SET @ParentProfileID = (SELECT parent_profile_id FROM core_profile
  36.             WHERE profile_id = @ParentProfileID)
  37.     END
  38.  
  39.     RETURN @ProfilePath
  40. END
  41.  
  42. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement