• Hi,

    I'm not sure what else you are doing with this data - but I don't think you need to loop through all your rows and put everything into a table variable as you have.

    Try something like this (it should be roughly correct, but check the columns against your database). This concatenates all the values (make sure they are varchar) and then joins the next row on... etc

    DECLARE @var varchar(max)

    SELECT @var = COALESCE(@var + ', ', '') + cd.KeyValue + ' Note - ' + rec.userTitle + ', ' + CONVERT(varchar(20), rec.RecommendationDate, 103) + CHAR(13) + rec.Details + CHAR(13)

    FROM t_table rec LEFT OUTER JOIN t_ControlData cd on rec.code= cd.KeyCode and cd.KeyName = 'name'

    WHERE rec.id= 2508 ORDER BY cd.KeyIndex ASC

    SELECT @var

    B