Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
 
   WITH ChildOrgList As (
      SELECT 1 as OrgLevel,
ChildOrg.[CHART_CD],ChildOrg.[ORG_UC_LEVEL_CD], ChildOrg.[ORG_CD],ChildOrg.[ORG_NM],
ChildOrg.[ORG_PARENT_ORG_CD], ChildOrg.[ORG_ROLLUP_LEVEL01_CD], ChildOrg.[ORG_ROLLUP_LEVEL02_CD], 
ChildOrg.[ORG_ROLLUP_LEVEL03_CD], ChildOrg.[ORG_ROLLUP_LEVEL04_CD], ChildOrg.[ORG_ROLLUP_LEVEL05_CD], 
ChildOrg.[ORG_ROLLUP_LEVEL06_CD]
            FROM [dssdwhs_kfsods].[dbo].[kfs_d_org] as ChildOrg WHERE
ChildOrg.CHART_CD = <kfsChartCode>
and ChildOrg.ORG_CD = <kfsOrgCode>
       UNION ALL
       SELECT Child.OrgLevel+1 as OrgLevel,
ParentOrg.[CHART_CD],ParentOrg.[ORG_UC_LEVEL_CD], ParentOrg.[ORG_CD],ParentOrg.[ORG_NM],
ParentOrg.[ORG_PARENT_ORG_CD], ParentOrg.[ORG_ROLLUP_LEVEL01_CD], ParentOrg.[ORG_ROLLUP_LEVEL02_CD], 
ParentOrg.[ORG_ROLLUP_LEVEL03_CD], ParentOrg.[ORG_ROLLUP_LEVEL04_CD], ParentOrg.[ORG_ROLLUP_LEVEL05_CD], 
ParentOrg.[ORG_ROLLUP_LEVEL06_CD]
            FROM [dssdwhs_kfsods].[dbo].[kfs_d_org] as ParentOrg
              INNER JOIN ChildOrgList as Child
               ON Child.[ORG_PARENT_ORG_CD] = ParentOrg.ORG_CD
            /*WHERE  ParentOrg.ORG_CD  <> 'UNIV'*/  )
    SELECT ML.MLv-L.OrgLevel+1 OrgLevNo, L.[ORG_UC_LEVEL_CD], L.[CHART_CD], L.[ORG_CD],
L.[ORG_NM], L.[ORG_PARENT_ORG_CD], L.[ORG_ROLLUP_LEVEL01_CD], L.[ORG_ROLLUP_LEVEL02_CD], 
L.[ORG_ROLLUP_LEVEL03_CD], L.[ORG_ROLLUP_LEVEL04_CD], L.[ORG_ROLLUP_LEVEL05_CD], 
L.[ORG_ROLLUP_LEVEL06_CD] 
from ChildOrgList L
    INNER JOIN
    (SELECT  [CHART_CD], MAX(OrgLevel) MLv from ChildOrgList     group
by [CHART_CD]) ML
 ON L.CHART_CD = ML.CHART_CD order by 1

...