Полезная функция для получения списка элементов измерения из куба.
Вызывается табличная функция:
1 |
select * from [scripts].[getElementListFromCube] ('Accounts','Cube1') |
Код табличной функции:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
USE [custom] GO /****** Object: UserDefinedFunction [custom].[scripts].[getElementListFromCube] ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [scripts].[getElementListFromCube] ( @vDimName nvarchar(50), @vCubeCalc nvarchar(50) ) RETURNS @elementList TABLE ( element nvarchar(50) ) as BEGIN declare @elementsHPLApps table(ElementCode nvarchar(50), Cube1 nvarchar(50), Cube2 nvarchar(50), Cube3 nvarchar(50)); insert into @elementsHPLApps SELECT tbl2.OBJECT_NAME ElementCode, tbl1.USED_IN & 2 Cube1, tbl1.USED_IN & 1 Cube2, tbl1.USED_IN & 4 Cube3 FROM [db_apps].[dbo].[HSP_MEMBER] tbl1 LEFT JOIN [db_apps].[dbo].[HSP_OBJECT] tbl2 ON tbl1.MEMBER_ID = tbl2.OBJECT_ID WHERE tbl1.DIM_ID IN ( SELECT OBJECT_ID FROM [db_apps].[dbo].[HSP_OBJECT] WHERE OBJECT_ID IN ( SELECT [DIM_ID] FROM [db_apps].[dbo].[HSP_DIMENSION] ) AND OBJECT_NAME = @vDimName ) and tbl2.OBJECT_TYPE<>45; if UPPER(@vCubeCalc)='Cube1' INSERT INTO @elementList select ElementCode from @elementsHPLApps where Cube1<>0; else if UPPER(@vCubeCalc)='Cube2' INSERT INTO @elementList select ElementCode from @elementsHPLApps where Cube2<>0; else if UPPER(@vCubeCalc)='Cube3' INSERT INTO @elementList select ElementCode from @elementsHPLApps where Cube3<>0; RETURN; END; GO |
Leave a Reply