A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
String_agg does it in a defined way. It is an aggregate function.
SELECT with variable assignment is only well defined when the SELECT statement returns a single row. The Docs says that if you say:
SELECT @x = col FROM tbl
@x will be assigned the value from the last row, but "last row" has no meaning in a relational database.