行在sql server2008中串联 [英] row concatenate in sql server2008

查看:70
本文介绍了行在sql server2008中串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,

我有以下数据.我需要的数据将是sql server2008中的一行像

输入:

ID名称标记
1 ABC 50
1 ABC 60
1 ABC 70

输出:
1 ABC 50,60,70

Dear sir,

I have following data. i need the data will be one line in sql server2008 Like

Input:

ID Name Marks
1 ABC 50
1 ABC 60
1 ABC 70

Output:
1 ABC 50,60,70

推荐答案



您可以在下面的查询中查询结果,

Hi,

you can use below query for result,

DECLARE @Marks VARCHAR(8000)
SELECT @Marks = COALESCE(@Marks + ', ', '') + Marks FROM tableName 
SELECT @Marks



谢谢
-Amit.



Thanks
-Amit.


COALESCE(Transact-SQL) [ ^ ]
COALESCE接受一个或多个相同数据类型的列名. COALESCE函数按照列的顺序检查每列的值,并返回第一个非缺失值.如果仅列出一列,则COALESCE函数返回该列的值.如果缺少所有参数的所有值,则COALESCE函数将返回缺少的值.

Coalesce函数 [使用SQL Server 2008将多行连接为单个文本字符串 [ ^ ]
将多行连接为一列 [
COALESCE (Transact-SQL)[^]
COALESCE accepts one or more column names of the same data type. The COALESCE function checks the value of each column in the order in which they are listed and returns the first nonmissing value. If only one column is listed, the COALESCE function returns the value of that column. If all the values of all arguments are missing, the COALESCE function returns a missing value.

Coalesce Function[^]
Concatenate many rows into a single text string using SQL Server 2008[^]
Concatenate multiple rows into one column[^]


这篇关于行在sql server2008中串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆