HiI have the following table...USE [TestDB]GO/****** Object: Table [dbo].[ProductsTree] Script Date: 2014-01-21 07:22:57 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[ProductsTree]( [NodeID] [int] IDENTITY(1,1) NOT NULL, [ParentNodeID] [int] NULL, [Text] [nvarchar](50) NULL, [Active] [bit] NULL, CONSTRAINT [PK_ProductsTree] PRIMARY KEY CLUSTERED ( [NodeID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOINSERT INTO ProductsTree (Text,ParentNodeID,Active) VALUES ('Folder 1', NULL, 1)INSERT INTO ProductsTree (Text,ParentNodeID,Active) VALUES ('Item 1', 1, 1)INSERT INTO ProductsTree (Text,ParentNodeID,Active) VALUES ('Item 2', 1, 1)INSERT INTO ProductsTree (Text,ParentNodeID,Active) VALUES ('SubFolder 1', 1, 1)INSERT INTO ProductsTree (Text,ParentNodeID,Active) VALUES ('Item 1', 4, 0)INSERT INTO ProductsTree (Text,ParentNodeID,Active) VALUES ('Item 2', 4, 1)INSERT INTO ProductsTree (Text,ParentNodeID,Active) VALUES ('SubFolder 2', 4, 1)INSERT INTO ProductsTree (Text,ParentNodeID, Active) VALUES ('Item 3', 7, 0)INSERT INTO ProductsTree (Text,ParentNodeID, Active) VALUES ('Item 4', 7, 0)
The table have a relationship between ParentNodeID and NodeID that is used to create a tree structure. I wonder if its possible to check and only display "folders" that have active nodes in them. For example the "Subfolder 2" only have inactive nodes in itself, therfore that whole subfolder and its nodes should not be displayed, and this should apply all the way meaning if there is further more subfolders that meet the same condition thoose should not be displayed either. Can this be achieved?