Unanswered: Concatenate Multiple Records Into One Field
Someone please help!. I am trying to create a view in SQL Server 2000 to use for a report but I am having problems with concatenating multiple values into one field. In my example below I am trying to list all records in my queried table in columnA then concatenate a list of all other records that share the same value in column B of the queried table into another field. If there are no other matches for a row in columnA then I would leave the corresponding field in columnB blank. Thanks in advance.
create function ConcatFld (@RowId int, @RowVal char(1))
returns varchar(100) AS
declare @Ret varchar(100)
select @Ret= @Ret + cast(ColA as varchar)+',' from Tbl1 where ColB=@RowVal and ColA<>@RowId
if len(@Ret) > 0
set @Ret = left(@Ret,len(@Ret)-1)