sqlserver merges a certain field information into one line, separated by commas

Implementation: use for xml path('') and stuff
effect:
insert image description here

sql statement

SELECT
	stuff(
		( SELECT ',' + su.user_name FROM sys_user su WHERE su.user_id IN ( '87', '86' ) FOR xml path ( '' ) ),
		1,
		1,
	'' 
	) AS user_name

Guess you like

Origin blog.csdn.net/fortunate_leixin/article/details/128130130