STRING_AGG with distinct values

I'm currently using STRING_AGG to display a list of barcodes per SKU. Unfortunately, our database includes duplicate barcodes, and the result displays all of them. For example, "1234, 5678, 1234, 5678."

I understand that I can use SELECT DISTINCT to only display unique barcode values, but I'm not sure how to implement DISTINCT in only one column. Is there a way to resolve this or a better way to go about this issue?

Our current code, simplified, looks as below:

SELECT StoreCode,
	SKU,
	STRING_AGG(Barcode, ', '),
FROM ItemSummaryView
	WHERE SKU = @SKU
GROUP BY StoreCode, SKU
ORDER BY StoreCode, SKU

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.