Concatenate Columns in Stored Procedure I have a stored procedure which returns a weekly result from input parameters start date and end date. I am getting multiple rows in the result.

Requirement: I want to add the results of columns in a single column. Below is my final query. From this I want to concatenate the result:

SET @sqlText = 
    N'SELECT ['+REPLACE(@columns,',','],[') + ']' +
    ' 
    FROM dbo.timesheet 
    WHERE
        month ='''+ @strMonth+''' 
        AND [Task ID] IN
        (
            SELECT TaskID 
            FROM ManageTasks 
            WHERE
                TeamMemberUserID ='+  Cast(@UserID AS VARCHAR(max)) +
        ')'

--Here I want to add the columns result and need to show as single column

PRINT @sqlText
EXEC (@sqlText)
Use FOR XML PATH

Sample from TSQL – Concatenate Rows using FOR XML PATH() - sqlandme.com

SELECT      CAT.Name AS [Category],
            STUFF((    SELECT ',' + SUB.Name AS [text()]
                        — Add a comma (,) before each value
                        FROM Production.ProductSubcategory SUB
                        WHERE
                        SUB.ProductCategoryID = CAT.ProductCategoryID
                        FOR XML PATH('') — Select it as XML
                        ), 1, 1, '' )
                        — This is done to remove the first character (,)
                        — from the result
            AS [Sub Categories]
FROM  Production.ProductCategory CAT


Without FOR XML PATH



With FOR XML PATH