我的表格.rar
(20.27 KB, 下载次数: 9)
Option Explicit
Sub A()
Dim ARR, BRR(1 To 9, 1 To 50), I%, J%, M%, SQL$, S$, TMP
Dim CNN As New cConnection
Dim RS As New cRecordset
ARR = Sheet1.Range("A1").CurrentRegion
CNN.CreateNewDB
SQL = "CREATE TABLE A (机构,model,合同号,有效合同,客户名,城市,电话,电话所属人,电话类型,与客户关系)"
CNN.Execute SQL
CNN.BeginTrans
For I = 2 To UBound(ARR)
S = ""
For J = 1 To UBound(ARR, 2)
S = S & "'" & ARR(I, J) & "',"
Next
S = Left(S, Len(S) - 1)
SQL = "INSERT INTO A VALUES(" & S & ")"
CNN.Execute SQL
Next
CNN.CommitTrans
SQL = "SELECT 机构,model,GROUP_CONCAT(DISTINCT(合同号)),有效合同,客户名,城市," _
& "GROUP_CONCAT(电话||""|""||电话所属人||""|""||电话类型||""|""||与客户关系||""|"","""") AS T FROM A " _
& "GROUP BY 机构,model,有效合同,客户名,城市 ORDER BY 客户名"
RS.OpenRecordset SQL, CNN
Do While Not RS.EOF
M = M + 1
For J = 0 To 5
BRR(M, J + 1) = RS.Fields(J)
Next
TMP = Split(RS.Fields(6), "|")
For I = 0 To UBound(TMP)
BRR(M, I + 7) = "'" & TMP(I)
Next
RS.MoveNext
Loop
Sheet2.Activate
[A2:AZ99] = ""
[A2].Resize(RS.RecordCount, 50) = BRR
Set RS = Nothing
Set CNN = Nothing
End Sub
|