Advertisement

02.09.2007 at 02:52PM PST, ID: 22157191
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Select Heirarchical Data Into Flat Resultset

Asked by SonOfPirate in MS SQL Server

I have to develop a database solution that will allow a query to return a single, flat resultset based on data contained in a heirarchical structure.  Let me explain...

All data is maintained using a container approach based on the company's organizational structure.  At the core of this is the OrganizationalUnits table with the following schema:

    UniqueID uniqueidentifier (PK)
    Name nvarchar(50)
    ParentOU uniqueidentifier (FK)

Each user is associated with an OU but they can be assigned to any level in the heirarchy.  For example, a Division Manager would be associated with the OU for the division whereas an Design Engineer would belong to the applicable department underneath the division.

When a new record is created in the database, let's use the Customers table for our discussion, the record is marked with the OU of the user that created it.  So, the Customers table schema is similar to:

    UniqueID uniqueidentifier (PK)
    OU uniqueidentifier (FK)
    Name nvarchar(50)
    :
    :

The heirarchy that we have is currently 4 levels deep (but may be changing as the company restructures this year): Company->Division->Group->Department

Anyway, the query needs to return all records from the Customers table corresponding to the current user's organizational unit AND all child OUs.  In other words, if the current user belongs to a department level OU, the query is nice and straight forward.  But, if the user is at the divisional level, the query needs to return records from that OU as well as all of the child groups and their child departments.

Unfortunately, because the depth of the heirarchy is variable today and in the future, I don't know where to begin.  I know that this is a common data structure today, so I'm hoping someone has crossed this bridge before and can point me in the right direction.  Thanks in advance.
Start Free Trial
[+][-]02.09.2007 at 03:40PM PST, ID: 18505383

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Sign Up Now!
Solution Provided By: nigelrivett
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.09.2007 at 09:15PM PST, ID: 18506131

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43