Home Forums SQL Server 2012 SQL Server 2012 - T-SQL Trying to build a report menu from data stored in two tables in SQL Database RE: Trying to build a report menu from data stored in two tables in SQL Database

  • sribe, while your query does remove the category for this particular set of test data, my question is a bit more general in nature. This test data is just one possible way of setting up the categories/sub categories, and my program will actually be able to allow the end users to setup their own categories/sub categories for the reporting. Your query will only remove the category if no subcategories reference it, but what I am wanting to do is to remove all categories (and their subcategories), if there are no reports (which are kept in a different table), which link to either the main category or any of its subcategories.

    For example, if I had a report that was linked to Test Sub Sub Sub Category 3, then Test Category 3, Test Sub Category 3, Test Sub Sub Category 3, and Test Sub Sub Sub Category 3 should all be visible (and in the test data, Report 5 is linked to this category.) But, if Report 5 was linked to, for example, Test Category 3, then none of the subcategories for Test Category 3 should be displayed, only the main test Category 3. Or if that report was linked to Test Category 4, Test Category 3 and all subcategories would be hidden, and Test Category 4 would be displayed.

    Hope that clears up what I am looking for. Again, this may not be possible with a query from the database, and if not that's fine. I am just trying to make sure that I am not missing something.