Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
masond
Constraint Violating Yak Guru
447 Posts |
Posted - 2013-05-09 : 10:12:45
|
Hey guys, I don’t use this forum for ages, and then i have two problems in a day which has baffled me Aim – Creating a hierarchy structure Agent – Highest LevelCorp- Second Highest LevelChain – Third Highest LevelFDMS AccountNO – Fourth Highest LevelWithin my data i always have a Agent, However i don’t always have a corp, so what i need is a query that gets the chain number, and puts the chain number into the corp , and fdmsaccount no into chain, For eg 1Agent_Chain_No Corp_Chain_No Chain_Chain_No FDMSAccountNo878970001888 000000000000 000000000000 878000000884In this scenario the FDMSaccount would be the Corp Chain No Eg 2Agent_Chain_No Corp_Chain_No Chain_Chain_No FDMSAccountNo878970001888 878003000881 000000000000 878003000881In this scenario the FDMSaccount would be the Chain Chain No Eg 3 Agent_Chain_No Corp_Chain_No Chain_Chain_No FDMSAccountNo878970001888 000000000000 878230737883 878000004886In this scenario the Chain No would be the CorpChain No , and fdmsaccount no would be chain noHope this makes senseThis is my table SELECT [Agent_Chain_No],[Corp_Chain_No],[Chain_Chain_No],[FDMSAccountNo]FROM [FDMS].[dbo].[Dim_Outlet]i am trying to achieve the same as in this link http://cwebbbi.wordpress.com/2009/11/11/ragged-hierarchies-hidememberif-and-mdx-compatibility/ |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-10 : 00:41:38
|
I think best approach would be do this as a series of updates each covering different scenariosomething like UPDATE TableSET Corp_Chain_No = FDMSAccountNoWHERE Corp_Chain_No='000000000000'AND Chain_Chain_No = '000000000000'UPDATE TableSET Chain_Chain_No = FDMSAccountNoWHERE Corp_Chain_No <> '000000000000'AND Chain_Chain_No = '000000000000'UPDATE TableSET Corp_Chain_No = Chain_Chain_No,Chain_Chain_No = FDMSAccountNoWHERE Corp_Chain_No='000000000000'AND Chain_Chain_No <> '000000000000' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|