Conversion failed converting the varchar value ',' to int
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