请通过sql server 2008解决 [英] Please solve by sql server 2008

查看:77
本文介绍了请通过sql server 2008解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于表格是---



Given the table is ---

depot_code              dealer_code               dealer_child_code
---------------------------------------------------------------------
032                        70554                      70554
032                        70554                      77182







但我想将输出显示为 -






But i want to show the output as --

depot_code              dealer_code               dealer_child_code
---------------------------------------------------------------------
032                        70554                    70554, 77182







使用光标,请尽早帮助...



[edit]已添加代码块 - OriginalGriff [/ edit]




using cursor, please help as early as possible...

[edit]Code block added - OriginalGriff[/edit]

推荐答案

我喜欢使用的一种简单方法是:

One easy way i like to use is this:
create table #t (id int, name varchar(20))

insert into #t
values (1, 'Matt'), (1, 'Rocks'), (2, 'Stylus')

select  id
        ,Names = stuff((select ', ' + name as [text()]
        from #t xt
        where xt.id = t.id
        for xml path('')), 1, 2, '')
from #t t
group by id





i从这里得到了例子:

http://stackoverflow.com/questions/13639262/optimal-way-to-concatenate-aggregate-strings [ ^ ]



试试搜索tsql聚合字符串连接,这应该让你走在正确的道路上。



i got the example from here:
http://stackoverflow.com/questions/13639262/optimal-way-to-concatenate-aggregate-strings[^]

Try searching for "tsql aggregate string concatenation", that should put you on the right path.


这篇关于请通过sql server 2008解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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