|
模块:
Function hBTXT(TX As String, TB As String, FD As String, TJFD As String)
Dim conn As ADODB.Connection
Set conn = CurrentProject.Connection
Dim RecA As ADODB.Recordset
Set RecA = New ADODB.Recordset
Dim Str
Str = "select DISTINCT " & FD & " from " & TB & " where " & TJFD & "='" & TX & "'"
RecA.Open Str, conn, adOpenStatic, adLockReadOnly
Select Case RecA.RecordCount
Case 0
hBTXT = ""
Case 1
hBTXT = RecA.Fields(0)
Case Is > 1
hBTXT = RecA.Fields(0)
For i = 2 To RecA.RecordCount
RecA.MoveNext
hBTXT = hBTXT & "\" & RecA.Fields(0)
Next i
End Select
End Function
查询:
SELECT 表1.项目, Sum(表1.金额) AS 金额之总计, hBTXT([项目],"表1","资金","项目") AS 表达式1
FROM 表1
GROUP BY 表1.项目; |
|