Bingo, Bango, Boingo! This works a charm. For those that may stumble on this topic you can exactly copy TD's oh so helpful response to see how it works. And yes I am pretty new to SQL programming and yes this was definitely over my head. Other than personal help I think only reading a book was going to save me here.
If you are using Visual Studio - create the db tables as outlined above
1. Go to Server Explorer and connect to your DB
2. RMB Functions folder and choose New Function (type doesn't matter)
3. Delete everything in the function and cut/paste in
CREATE function dbo.fnConcatColors(@toy varchar(10))
RETURNS varchar(50)
AS
BEGIN
DECLARE @out varchar(50)
SELECT @out = COALESCE(@out + ', ' + color, color)
FROM m
WHERE toy = @toy
RETURN @out
END
4. RMB Stored Procedure folder and choose New. Delete all and cut/paste in:
SELECT toy, dbo.fnConcatColors(t1.toy) AS Colors
FROM t1
5. RMB the SQL block in your stored procedure and choose -> Design. Click execute and it will return exactly as you wanted.
6. Okay I know I am babying here, but I spent so much time on this today I have to share. If you had properly formed tables with ID columns for Toy and Color tables and the map referenced the ID's as opposed to directly referencing the colors you can use the following function and stored procedure to get your results.
CREATE PROCEDURE dbo.StoredProcedure1
AS
SELECT toy, dbo.GetToyColors(toyid) AS Colors
FROM t1
RETURN
------------------------------------------------------------------------------------------
CREATE FUNCTION dbo.GetToyColors(@toy int)
RETURNS varchar(50)
AS
BEGIN
Declare @out varchar(50)
SELECT @out = COALESCE(@out + ', ' + CAST(color as varchar), color)
FROM m INNER JOIN t2 ON m.colorid = t2.colorID
WHERE toyid = @toy
RETURN @out
End