"tmp" part - таблица для проверки запроса. Вам это не нужно, это для других читателей:)
CREATE TABLE #tmpCatInfo (ID int, CategoryName varchar(55), ParentID int, IsActive int)
INSERT INTO #tmpCatInfo
SELECT * FROM (VALUES (1, 'Toyota', NULL, 1)
,(2, 'Honda', NULL, 1)
,(3, 'Mitsubhi', NULL, 1)
,(4, 'Toyota GLI', 1, 1)
,(5, 'Toyota XLI', 1, 1)
,(6, 'Swift', 1, 1)
,(7, 'Honda Civic', 2, 1)
,(8, 'Honda City', 2, 1)) a(ID, CategoryName, ParentID, IsActive)
;
-- USE THIS PART
-- Change #tmpCatInfo on your table name
WITH CategoryInfo (ID, CategoryName, IsActive, Model)
AS
(
SELECT ci.ID as ID
, ci.CategoryName as CategoryName
, ci2.IsActive as IsActive
, ci2.CategoryName as Model
FROM #tmpCatInfo ci
JOIN #tmpCatInfo ci2 ON ci.ID = ci2.ParentID
)
SELECT CASE
WHEN row_number() over (PARTITION BY CategoryName ORDER BY (SELECT NULL)) = 1
THEN CategoryName
END AS
CatogoryName
, Model
FROM CategoryInfo
-- USE THIS PART