[SQL ] 在VBA中合併字串
資料庫名稱: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;
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.246.92.215
※ 文章網址: https://www.ptt.cc/bbs/Database/M.1507904285.A.297.html
Database 近期熱門文章
PTT數位生活區 即時熱門文章