Hi,
Using sql2012. Have a category table with main and sub categories.
Need all final categories under a main category.
Tried with passing parentID,but it shows only the first level categories.
catID categoryName parentCatID isFinal
100 vessels NULL NULL
101 vesselbyShape 100 NULL
102 glass vessels 100 Y
103 stone vessels 100 Y
104 vesselbyType 100 NULL
201 roundVessel 101 Y
204 paintedVessel 104 Y
DECLARE @myCategory table
(
catID int
, categoryName varchar(25)
, parentCatID int
, isFinal char(1)
);
INSERT INTO @myCategory VALUES
(
100,'vessels',NULL,NULL
),
(
101,'vesselbyShape',100,NULL
),
(
102,'glass vessels',100,'Y'
),
(
103,'stone vessels',100,'Y'
),
(
104,'vesselbyType',100,NULL
)
,
(
201,'roundVessel',101,'Y'
)
,
(
204,'paintedVessel',104,'Y'
)
SELECT * from @myCategory
Tried query:
SELECT
catID,
categoryName
FROM
@myCategory
WHERE
parentCatID = 100
AND
isFinal= 'y'
Expected output: 102,103,201,204