first create a function to return a csv for a given car then use the function in a select statement of all cars:set nocount onuse pubsgocreate table car (carid int identity(1,1) primary key, carname varchar(30))create table Category (Categoryid int identity(1,1) primary key, CategoryName varchar(30))gocreate table Car_Category (CarID int references car(carid), CategoryID int references category(categoryid))goinsert car (carname)select 'FordGT' union allselect 'Mustang' union allselect 'EscapeHybrid'insert Category (categoryName)select 'sports' union allselect 'luxury' union all select 'SUV' union allselect 'hybrid'goinsert Car_Category (carid, categoryid)select 1,1 union allselect 1,2 union allselect 2,1 union allselect 2,3 union allselect 3,4go--first create a function to return a csv for a given car:if object_id('dbo.CategoriesByCarID') > 0 drop function dbo.CategoriesByCarIDgocreate function dbo.CategoriesByCarID(@carid int)returns varchar(2000)asbegin declare @cats varchar(2000) select @cats = coalesce(@cats + ', ' + c.CategoryName, c.CategoryName) from Car_Category cc join Category c on c.categoryid = cc.categoryid where cc.carid = @carid order by c.categoryName return @catsendgo--now use the functionselect c.CarID ,c.CarName ,Categories = dbo.CategoriesByCarID(c.carid)from dbo.Car cdrop table Car_Categorygodrop table Cardrop table categoryBe One with the OptimizerTG