I have a query which outputs something like this:
+-------+----+--------------+
| F_KEY | EV | OTHER_COLUMN |
+-------+----+--------------+
| 100 | 1 | ..
You can do it easily enough with a function: Assumes you are going to be searching the same column/table all the time. Dynamic SQL needed if you want to be able to vary the columns/tables
CREATE FUNCTION [dbo].[fn_recursion]
(@F_KEY int)
RETURNS varchar(2000) AS
BEGIN
DECLARE @ReturnVal Varchar(2000)
SELECT @ReturnVal = COALESCE(@ReturnVal + ', ', '') + EV
FROM TABLE2
WHERE @F_KEY = @F_KEY
RETURN ISNULL(@ReturnVal,'')
END
GO
SELECT
F_KEY,
EV = [dbo].[fn_recursion](F_KEY),
OTHER_COLUMN
FROM
TABLE1
JOIN
TABLE2 ON F_KEY = TABLE2.ID
WHERE
EVENT_TIME BETWEEN '2011-01-01 00:00:00.000' AND '2011-12-31 23:59:59.999'
ORDER BY
EVENT_TIME ASC
GO
DROP FUNCTION [dbo].[fn_recursion]
GO