{"id":235,"date":"2014-01-22T13:55:51","date_gmt":"2014-01-22T13:55:51","guid":{"rendered":"http:\/\/www.decarl.com\/?p=235"},"modified":"2014-01-22T13:55:51","modified_gmt":"2014-01-22T13:55:51","slug":"maximo-hierarchies-report","status":"publish","type":"post","link":"https:\/\/www.decarl.com\/?p=235","title":{"rendered":"Maximo Hierarchies Report"},"content":{"rendered":"<p>I went through several options on making Location Hierarchy Reports, and found these queries to be quite beneficial. The code is different, depending on the backend being Oracle or Microsoft.<\/p>\n<h4>Oracle<\/h4>\n<p><span style=\"color: #008000;\">select level, lpad (&#8216; &#8216;, 8 * (level &#8211; 1)) || lh.location &#8220;LOCATION&#8221;, l.description, lh.parent, lh.siteid<\/span><br \/>\n<span style=\"color: #008000;\"> from lochierarchy lh, locations l<\/span><br \/>\n<span style=\"color: #008000;\"> where lh.location = l.location and lh.siteid = l.siteid and lh.siteid = &#8216;TXPANHANDLE&#8217;<\/span><br \/>\n<span style=\"color: #008000;\"> start with lh.location =&#8217;CANADIAN&#8217;<\/span><br \/>\n<span style=\"color: #008000;\"> connect by prior lh.location = lh.parent<\/span><\/p>\n<h4>Microsoft<\/h4>\n<p><span style=\"color: #008000;\">select lo.location, lh.parent, lo.description<\/span><br \/>\n<span style=\"color: #008000;\"> into #tempo<\/span><br \/>\n<span style=\"color: #008000;\"> from locations lo<\/span><br \/>\n<span style=\"color: #008000;\"> inner join lochierarchy lh on lh.location = lo.location<\/span><br \/>\n<span style=\"color: #008000;\"> where lo.status in (&#8216;OPERATING&#8217;, &#8216;ACTIVE&#8217;) and lh.parent not in (&#8216;DELETE&#8217;);<\/span><\/p>\n<p><span style=\"color: #008000;\">WITH Hierarchy<\/span><br \/>\n<span style=\"color: #008000;\"> AS ( SELECT parent AS RootID ,<\/span><br \/>\n<span style=\"color: #008000;\"> 1 AS [Level] ,<\/span><br \/>\n<span style=\"color: #008000;\"> &#8216;\\\\&#8217; + CAST(parent AS VARCHAR(MAX)) + &#8216;\\&#8217; + CAST(location AS VARCHAR(MAX))AS [Path] ,<\/span><br \/>\n<span style=\"color: #008000;\"> parent ,<\/span><br \/>\n<span style=\"color: #008000;\"> location<\/span><br \/>\n<span style=\"color: #008000;\"> FROM #tempo<\/span><br \/>\n<span style=\"color: #008000;\"> WHERE NOT parent IN ( SELECT location<\/span><br \/>\n<span style=\"color: #008000;\"> FROM #tempo )<\/span><br \/>\n<span style=\"color: #008000;\"> UNION ALL<\/span><br \/>\n<span style=\"color: #008000;\"> SELECT P.RootID ,<\/span><br \/>\n<span style=\"color: #008000;\"> P.[Level] + 1 ,<\/span><br \/>\n<span style=\"color: #008000;\"> P.[Path] + &#8216;\\&#8217; + CAST(C.location AS VARCHAR(MAX)) ,<\/span><br \/>\n<span style=\"color: #008000;\"> C.parent ,<\/span><br \/>\n<span style=\"color: #008000;\"> C.location<\/span><br \/>\n<span style=\"color: #008000;\"> FROM Hierarchy P<\/span><br \/>\n<span style=\"color: #008000;\"> INNER JOIN #tempo C ON P.location = C.parent<\/span><br \/>\n<span style=\"color: #008000;\"> )<\/span><br \/>\n<span style=\"color: #008000;\"> SELECT case level<\/span><br \/>\n<span style=\"color: #008000;\"> when 1 then &#8221;<\/span><br \/>\n<span style=\"color: #008000;\"> when 2 then &#8216; |&#8211;&#8216;<\/span><br \/>\n<span style=\"color: #008000;\"> when 3 then &#8216; | |&#8211;&#8216;<\/span><br \/>\n<span style=\"color: #008000;\"> when 4 then &#8216; | | |&#8211;&#8216;<\/span><br \/>\n<span style=\"color: #008000;\"> when 5 then &#8216; | | | |&#8211;&#8216;<\/span><br \/>\n<span style=\"color: #008000;\"> when 6 then &#8216; | | | | |&#8211;&#8216;<\/span><br \/>\n<span style=\"color: #008000;\"> when 7 then &#8216; | | | | | |&#8211;&#8216;<\/span><br \/>\n<span style=\"color: #008000;\"> when 8 then &#8216; | | | | | | |&#8211;&#8216;<\/span><br \/>\n<span style=\"color: #008000;\"> when 9 then &#8216; | | | | | | | |&#8211;&#8216;<\/span><br \/>\n<span style=\"color: #008000;\"> when 10 then &#8216; | | | | | | | | |&#8211;&#8216;<\/span><br \/>\n<span style=\"color: #008000;\"> else &#8216;XXX&#8217;<\/span><br \/>\n<span style=\"color: #008000;\"> end<\/span><br \/>\n<span style=\"color: #008000;\"> + location &#8216;Location Hierarchy&#8217;<\/span><br \/>\n<span style=\"color: #008000;\"> FROM Hierarchy<\/span><br \/>\n<span style=\"color: #008000;\"> ORDER BY [Path] ;<\/span><br \/>\n<span style=\"color: #008000;\"> drop table #tempo;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I went through several options on making Location Hierarchy Reports, and found these queries to be quite beneficial. The code is different, depending on the backend being Oracle or Microsoft. Oracle select level, lpad (&#8216; &#8216;, 8 * (level &#8211; &hellip; <a href=\"https:\/\/www.decarl.com\/?p=235\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4,5,6,12,10,11],"tags":[],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-maximo","category-maximo-5","category-maximo-6","category-maximo-7","category-oracle","category-sql","category-sql-server"],"_links":{"self":[{"href":"https:\/\/www.decarl.com\/index.php?rest_route=\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.decarl.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.decarl.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.decarl.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.decarl.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=235"}],"version-history":[{"count":7,"href":"https:\/\/www.decarl.com\/index.php?rest_route=\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/www.decarl.com\/index.php?rest_route=\/wp\/v2\/posts\/235\/revisions\/242"}],"wp:attachment":[{"href":"https:\/\/www.decarl.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.decarl.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.decarl.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}