我知道您可以这样做,因为我以前看过一次,但是我忘记了直到现在我都不需要这样做.
I know you can do this, because I've seen it done once before, but I forget where and up until now I haven't need to do it.
我有一个名为雇员"的表,它具有各种雇员数据(duh).我需要一个查询,该查询将对表中所有行的名字和姓氏进行选择,然后将它们全部组合成一个逗号分隔的字符串.
I have a table called Employees, and it has various employee data (duh). I need a query that will do a select on the first and last name of all rows in the table, and then contenate all of them into a comma delimited string.
例如,我有几行数据(比实际要多得多,但出于这个问题,我们假设仅两行),如下所示:
For example, I have a few rows (a lot more than that actually, but for the sake of this question just assume two) of data that look like:
FName LName ------- ----- Richard Prescott Jill Sentieri Carol Winger我需要选择一个能够以这种形式返回上述数据的选择:
I need to a select that can return the aforementioned data in this form:
Richard Prescott, Jill Sentieri, Carol Winger预先感谢您的帮助!
推荐答案使用合并.像这样:
DECLARE @Names varchar(1000) SELECT @Names = COALESCE(@Names + ', ', '') + Name FROM Employees更多推荐
连接单个查询中的选定列?
发布评论