VBA函数:
Public Function Combstr(tablename As String, fieldname As String, groupfield As String, groupvalue As String) As String
Dim resultstr As String
Dim rs As Recordset
Dim sql As String
sql = "select " & fieldname & " from " & tablename & " where " & groupfield & " = " & groupvalue
Set rs = CurrentDb.OpenRecordset(sql)
If rs.RecordCount > 0 Then
Do While Not rs.EOF
resultstr = resultstr & rs.Fields(0).Value
rs.MoveNext
Loop
End If
If resultstr <> "" Then resultstr = Mid(resultstr, 1)
Combstr = resultstr
End Function
SQL查询如下:按照orig_fid字段分组,然后将同组内ZB_text字段值进行拼接
SELECT orig_fid, combstr("zb_temp","ZB_text","orig_fid",orig_fid) AS zb
FROM zb_temp
GROUP BY orig_fid;