DECLARE @temp TABLE (Id varchar(MAX) NOT NULL, name varchar(MAX) NOT NULL ,itemtype varchar(50) NOT NULL );
INSERT @temp (Id,name,itemtype)
SELECT distinct STUFF((SELECT ',' + Item.Id FROM Items Item
INNER JOIN ProductDetails on Item.Id=ProductDetails.ItemsId
where Item.BrandsId in (select id from Brands) FOR XML PATH('')),1,1,'') AS ID,Item.ItemName,'Item' FROM Items AS Item
GROUP BY Item.ItemName
Select * from @temp
Loading

Manas MohapatraPosted Jan 8, 2016, 4:54 AM
Manas MohapatraPosted Jan 8, 2016, 5:15 AM
Abhilash J APosted Jan 8, 2016, 5:11 AM
Using this query I got result like this:-
Id= 1,2,3,4,4,5,6,7,9,10,11,12,12,13,14,15,16,17,18,19,20 etc...
and name is not showing alphabetically
But I want result like this Id =256,23,89,24, that is Id is respect to name with not repeat same name