Concatenating Column Values into a Comma-Separated List
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the TSQL syntax to format my output so that the column values appear as a string, seperated by commas. Example, my table CARS has the following: CarID CarName ---------------- 1 Porsche 2 Mercedes 3 Ferrari How do I get the car names as : Porsche, Mercedes, Ferrari 回答1: You can do a shortcut using coalesce to concatenate a series of strings from a record in a table, for example. declare @aa varchar (200) set @aa = '' select @aa = case when @aa = '' then CarName else @aa + coalesce(',' + CarName, '') end from Cars print @aa 回答2: