连接单个查询中的选定列?

编程入门 行业动态 更新时间:2024-10-26 04:22:32
本文介绍了连接单个查询中的选定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道您可以这样做,因为我以前看过一次,但是我忘记了直到现在我都不需要这样做.

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

更多推荐

连接单个查询中的选定列?

本文发布于:2023-10-14 11:49:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1490973.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!