Question: Below is table and expected result. What is the query to achieve this result Table : Test ID LOT 7065161 4 7065212 1 7065212 4 7065203 1 7065203 2 7065203 3 Expected Result of query ID LOT 7065161 4 7065212 1_4 7065203 1_2_3 Answer: Previous to SQL Server 2017 - I use to use the COALESCE function , but since SQL Server 2017 - a new function was introduced : STRING_AGG . According to MS documentation "Concatenates the values of string expressions and places separator values between them. The separator is not added at the end of string" There... Read more →