Press "Enter" to skip to content

String Concatenation with STRING_AGG()

Jack Vamvas takes us through a fairly recent quality of life improvement:

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

Click through to learn the easiest way to do this as of SQL Server 2017.