Create Table A_Test (Name Varchar (20) Zhang ',' General User ') INSERT INTO A_TEST VALUES (' Zhang ',' Feng Xiaoqiang ') INSERT INTO A_TEST VALUES (' Chang ',' General User ')
Create Function Join_Str (@content varchar (100)) Returns varchar (2000) asbegindeclare @str varchar (2000) set @str = '' select @ str = @ Str ',' RTRIM (role2) from a_test where [name] = @ContentSelect @ Str = Right (@ Str, Len (@str) -1) Return @strendgo
Select [name], dbo.join_str ([name]) role2 from a_test group by [name]
Select distinct [name], dbo.Join_STR ([Name]) from a_test
Select dbo.join_str ('Zhang')