我正在使用Access并拥有此sql
SELECT land.id,land.official_name,vaksiner.vaksiner FROM land INNER JOIN (vaksiner INNER JOIN land_sykdom ON vaksiner.id = land_sykdom.sykdom) ON land.kort = land_sykdom.land ORDER BY land.official_name
sql给我一个这样的结果:
id official_name vaksiner 1 a A 1 a C 2 b A 2 b B 2 b C
但我想结合结果,使它看起来像这样:
id official_name vaksiner 1 a A,C 2 b A,B,C
解决方法
参见Allen Browne的Concat相关函数(
Concatenate values from related records)
如果将现有查询保存为qryVaksinerRaw,则可以构建这样的新查询以生成您所追求的结果.
SELECT DISTINCT id,official_name,ConcatRelated("vaksiner","qryVaksinerRaw","id = " & [id]) AS vaksiner FROM qryVaksinerRaw;
Public Function ConcatRelated(strField As String,_
并继续包括
End Function
然后将复制的文本粘贴到模块中.
注意ConcatRelated()将可用于从Access内部运行的查询.但是,像任何自定义VBA函数一样,它不能用于从外部Access运行的查询(如经典ASP,.Net等)