通过用isnull()把某一列下的所有数据组成一个字符串
DECLARE @str VARCHAR(max) begin --select * from [CONVERSEMDM].[mdm].[ViewProduct] where validity=1 AND SEASON in ( ''+REPLACE(@Season,',',''',''')+'') AND CN_Digital_Buying_Flag='Y' --= 'select * from [CONVERSEMDM].[mdm].[ViewProduct] where validity=1 AND SEASON in ('''+REPLACE(@Season,',',''',''')+''')' SET @str='' SELECT @str= isnull(@str,'')+RoleName+',' FROM [Converse_MDMWEB].[dbo].[System_RoleInfo] WHERE validity=1 SELECT @str end
效果: