[SQL ] 在VBA中合并字串

楼主: licheer (Keep The Faith)   2017-10-13 22:18:03
数据库名称:MS SQL
内容/问题描述:
NAME MEMO
1 A,B
2 C,D,E,F
1 J,K,L
1 M,N
==========================
1 A,B,J,K,L
下面这个方法最多只能加两次,第三次以上M,N就没办法了
请问可以怎么写才能把所有字段的字串相加呢? 谢谢
SELECT name,(select top 1 memo from a as k where k.name = i.name order by
memo desc) & (select top 1 (',' & memo) from a where name in ((select name
from a as j where i.name = j.name group by name having count(name) > 1))
order by memo ) as memo FROM a AS i GROUP BY name order by name desc;

Links booklink

Contact Us: admin [ a t ] ucptt.com