Referring to How to make a query with group_concat in sql server i referenced the above link to resolve the duplicates and combine multiple images in the same field (much like the one referenced in that link) but instead of getting 6-7 images per item, i'm getting all images for all items in every item. also with joined tables, group by isn't working.
select ItemId, Pictures = STUFF((
SELECT '|' + Title
FROM dbo.Pictures
WHERE ItemID = ItemID
FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, '')
from dbo.Pictures
group by ItemID
group by works with this piece of code but with i get images for all items in each item.
the code that i need this to work with is,
USE SixBit;
GO
SELECT dbo.Active.[Item ID], CONCAT (SixBit.dbo.Active.[Stock Number], ' ', Active.Stock) AS StockNumber,
CONCAT(SixBit.dbo.Active.Year, ' ', SixBit.dbo.Active.Model, ' / Stock Number - ', Active.[Stock Number], ' ', Active.Stock, ' / ', Active.Title, ' Interchange Part Number / ', Active.[Interchange Part Number], '/ ITEM CONDITION ', Active.[eBay Condition Description], Active.[Conditions and Options]
) AS Descrition, CONCAT(Active.Year, ' ', Active.Model) AS Category, Active.Title AS Name, CONCAT(SixBit.dbo.Active.Year, ' ', SixBit.dbo.Active.Model, ' / Stock Number - ', Active.[Stock Number], ' ', Active.Stock, ' / ', Active.Title,' Interchange Part Number / ', Active.[Interchange Part Number], '/ ITEM CONDITION ', Active.[eBay Condition Description], Active.[Conditions and Options]
) AS DescritionLong, Active.[Weight Major], Active.[Dimension Length], Active.[Dimension Width], Active.[Dimension Depth], Active.[Qty On Hand], Active.[Fixed Price], Active.SKU, Active.Model AS Manufacture, dbo.Listings.StartDate,
Pictures = STUFF((
SELECT '|' + CONCAT ('"', dbo.Pictures.Title, '"')
FROM dbo.Pictures
WHERE ItemID = ItemID
FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')
FROM Listings INNER JOIN
Active ON Listings.ListingID = Active.[Item ID] INNER JOIN
Pictures ON Active.[Item ID] = Pictures.ItemID
where dbo.Active.[Item ID] <= 10
group by doesn't work with this code and like above, all images are in every item, so all items have all images. p.s, the concat i'm using in STUFF is because the results contain "$" and i need to wrap them in " " for importing purposes.
thanks in advance for any help i can get.