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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-09-30 : 07:24:45
|
| Malcolm writes "Hi,I am working on a solution to enable users to select the various elements of a hierarchy from different levels and return the data as a report.For example the indented list would appear as follows:Deposits,placmements,loans & securities (Level 1) --Deposits,placements & loans (Level 2) ----Unlisted corporations (Level 3) --Securities (Level 2) ----Securitised instruments (Level 3)Unlisted (Level 1) --Corporations & private unit trusts (Level 2) --Retail/Public offer trusts (Level 2) ----Property (Level 3) ----Equities (Level 3) ----Cash management (Level 3) ----Other (Level 3)If you create seperate tables for each level and then link these to form the above hierarchy then you are able to return the full result set. The problem I have is thats its possible that a user may select for example 'Property (Level 3)' and 'Securities (Level 2)'. Because they are from different levels and more importantly branches then then the query returns a empty result set. The table struture would be some like the following:-Level_1_tblLevel_1_Key Level_1_Description-----------------------------------------------------1 Deposits,placmements,loans & securities 2 UnlistedLevel_2_tblLevel_1_Key Level_2_Key Level_2_Description-----------------------------------------------------1 20 Deposits,placements & loans1 30 Securities2 40 Corps & private unit trusts 2 50 Ret/Public offer trusts Level_3_tblLevel_2_Key Level_3_Key Level_3_Description-----------------------------------------------------20 200 Unlisted corporations30 300 Securitised instruments 40 400 Property 40 500 Equities40 600 Cash management 40 700 OtherSQL used would be the following:SELECTa1.Level_1_Description,a2.Level_2_Description,a3.Level_3_DescriptionFROMLevel_1_tbl a1inner join Level_2_tbl a2on a1.Level_1_Key=a2.Level_1_Keyinner join Level_3_tbl a3on a2.Level_1_Key=a3.Level_1_KeyAny help would be greatly appreciated I've been looking for a solution for a while. I'd imagine that the table data need to be modelled in another way?Regards,Malcolm" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
rfrancisco
Yak Posting Veteran
95 Posts |
Posted - 2005-09-30 : 12:45:20
|
| You can also look at this link:http://www.sql-server-helper.com/functions/get-tree-path.aspx |
 |
|
|
|
|
|