Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在sql server中将多行连接到一个字段中_Sql_Sql Server_Database - Fatal编程技术网

如何在sql server中将多行连接到一个字段中

如何在sql server中将多行连接到一个字段中,sql,sql-server,database,Sql,Sql Server,Database,使用简单的查询,我可以做如下事情 SELECT hobbies FROM peoples_hobbies WHERE person_id = 5; 并获得: shopping fishing coding 但我只想要一行,一列: shopping, fishing, coding 参考—— 我想在sql server中实现这一点???sql server不太支持聚合字符串连接。但你可以做到: select stuff((select ', ' + hobbies

使用简单的查询,我可以做如下事情

SELECT hobbies FROM peoples_hobbies WHERE person_id = 5;
并获得:

shopping

fishing  

coding
但我只想要一行,一列:

shopping, fishing, coding
参考——


我想在sql server中实现这一点???

sql server不太支持聚合字符串连接。但你可以做到:

select stuff((select ', ' + hobbies
              from peoples_hobbies
              where person_id = 5
              for xml path ('')
             ), 1, 2, '') as hobbies;