We are trying to put together a comma delimited list for a report that lists our Managers and their respective stores (e.g. Jim 3,4,5,6,33,22,56)
The manager is of type varchar (50) and the store_number is of type smallint
since we need to put the store_number into a string we cast the store_number as a varchar
The below query puts the store numbers in a row but duplicates numbers and I need to incorporate the managers name in there (RVP_Name)
DECLARE @storenum varchar(max)
Select
@storenum = Coalesce(@storenum+',','') + cast(store_number as varchar(max))
From vw_territory t
select @storenum
Resulting in: 4,4,1,1,1,1,1,7,7,8,8,11,11,4,4,4,4,4,9,9,6,6,6,6,6,13,13,13,14.........................
Any assistance with this would be helpful