ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.Function to get comma (delimited) separated values from Table in SQL Server<p>Hi <a class="username" rel="nauna"> nauna</a>,</p> <p>Refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">DROP FUNCTION GetCommaSeparatedString GO CREATE FUNCTION GetCommaSeparatedString(@City NVARCHAR(15)) RETURNS VARCHAR(MAX) AS BEGIN DECLARE @Output VARCHAR(MAX) SELECT @Output = COALESCE(@Output + &#39;,&#39;, &#39;&#39;) + CAST(EmployeeId AS VARCHAR(5)) FROM Employees WHERE City = @City RETURN @Output END GO SELECT dbo.GetCommaSeparatedString(&#39;London&#39;) AS Ids</pre> <p>&nbsp;</p>, 13 May 2019 04:40:07 GMT