|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
6、
SELECT a.合同号, a.付款日期, a.最迟装运日期
FROM 表2:付款及到货情况 A where a.付款日期=(select max(付款日期) from 表2:付款及到货情况 where 合同号=a.合同号)
7、Access多行合并成一行的实现
Public Function concateColumn(sTable As String, sRow As String, sCol As String, vRow As String, Optional delimiter As String = "")
Dim dbsNorthwind As DAO.Database
Dim rs As DAO.Recordset
Dim sSQL As String
Dim sResult As String
Dim i As Integer
sResult = ""
sSQL = "select " & sCol & " from " & sTable & " where " & sRow & "=""" & vRow & """"
Set dbsNorthwind = CurrentDb
Set rs = dbsNorthwind.OpenRecordset(sSQL, dbOpenDynaset)
For i = 0 To rs.RecordCount - 1
If i = rs.RecordCount - 1 Then
sResult = sResult & rs.Fields(0).Value
Else
sResult = sResult & rs.Fields(0).Value & delimiter
End If
rs.MoveNext
Next i
rs.Close
Set rs = Nothing
Set dbsNorthwind = Nothing
concateColumn = sResult
End Function
调用:
SELECT 查询5.规格, concateColumn('查询5','规格','名称',规格,"/") AS 合并的名称
FROM 查询5; |
|