SELECT DISTINCT transfer, dbo.ufn_binlist(transfer) FROM mytable1 -- UDF ufn_binlist CREATE FUNCTION ufn_binlist (@transfer char(10)) RETURNS varchar(1024) AS BEGIN DECLARE @str varchar(1024) SELECT @str = ISNULL(@str + ', ', '') + bin FROM mytable1 WHERE transfer = @transfer RETURN @str END>
>Transfer # Item # Bin >---------- -------------------- ---------- >1000000018 AEROCHAIR-A1 MASTER >1000000019 BRACKET MASTER >1000000020 BRACKET MASTER >1000000021 BRACKET MASTER >1000000022 BRACKET DEFECTIVE >1000000022 BRACKET MASTER >1000000023 AEROCHAIR-A1 DEFECTIVE >1000000023 AEROCHAIR-A1 MASTER >1000000024 AEROCHAIR-A1 MASTER >1000000024 AEROCHAIR-A1 DEFECTIVE >1000000024 AEROCHAIR-A1 RECEIVING>
>Transfer # Item # Bin >---------- -------------------- ---------- >1000000018 AEROCHAIR-A1 MASTER >1000000019 BRACKET MASTER >1000000020 BRACKET MASTER >1000000021 BRACKET MASTER >1000000022 BRACKET DEFECTIVE, MASTER >1000000023 AEROCHAIR-A1 DEFECTIVE, MASTER >1000000024 AEROCHAIR-A1 DEFECTIVE, MASTER, RECEIVING>Note that the result set was group bu Transfer # + Item # and the Bin value should be comma delimeted for Transfer # and Item # that occurs several times. The possible value of the bin field depends on many entries in the said table.