Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9233195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:29:40+00:00 2026-06-18T06:29:40+00:00

So I have a table that has divisions and sub-divisions. The structure is as

  • 0

So I have a table that has divisions and sub-divisions. The structure is as follows:

COMPANYID | DIVISIONID | DIVISION | PARENTID
    1     |     1      | North    | NULL
    1     |     2      | South    | NULL
    1     |     3      | East     | NULL
    1     |     4      | West     | NULL
    1     |     5      | Sales    | 1
    1     |     6      | Service  | 1
    1     |     7      | Sales    | 2
    1     |     8      | Service  | 2
    1     |     9      | Sales    | 3
    1     |     10     | Service  | 3
    1     |     11     | Sales    | 4
    1     |     12     | Service  | 4

The idea behind the table is that the data would indicate all of those divisions/subdivisions are the for the same company. Anything with a null PARENTID is a “Division” and anything that has a PARENTID is a “Sub-Division”. There will be a max of 2 tiers (Division –> Subdivision). This table would create the following hierarchy:

Company 1
    North
        Sales
        Service
    South
        Sales
        Service
    East
        Sales
        Service
    West
        Sales
        Service

I am trying to make an SSRS report that shows details about the company including a table with all the divisions and sub-divisions. I am using the following query to retrieve a list of all the divisions and subdivisions:

SELECT division, parentid
FROM division
WHERE companyid=@companyid

@companyid is a parameter for the report. My thought process is that I want create a table that has a Parent group and a Detail group where the Parent group would be all those rows that have a null PARENTID and then the Detail group would list all rows whose PARENTID equals the divisionid of Parent row. I’m just not sure how to set that up in the groups. Filters? Separate queries? Do it in the SQL query?

Any and all help is greatly appreciated! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:29:42+00:00Added an answer on June 18, 2026 at 6:29 am

    For a simple hierarchy with a maximum of 2 levels you can just join the table on itself:

    SELECT D1.CompanyId, D1.DivisionId, D1.Division, D2.Division AS Subdivision
    FROM DivisionTable D1
    INNER JOIN DivisionTable D2 ON D1.DivisionId = D2.ParentId AND D1.CompanyId = D2.CompanyId
    WHERE D1.CompanyId = @CompanyId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has records with a structure similar to this.. ID
I have a table that has account numbers in (account_num) and user profiles (profile_id).
I have a table that has two datetime columns (one for start time and
I have a table that has duplicate email address, I need to insert just
I have a table that has no primary key, and one cannot be created
I have one table that has two fields - ID1 and ID2 ID1 can
I have a table that has an AUTO_INCREMENT field. Currently, it is also a
I have a table that has three different date columns, so I set each
I have one table that has sales records and another table that has additional
i have a table that has event name and event date. if i want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.