|
kangking 发表于 2012-2-28 10:13
感谢回复!
按你的思路,就是在ACCESS中,我试了一下,速度比原来的查询慢。
(我的查询句,稍有点复杂 ...
这里改成了交叉表查询后测试完成时间是1s,——因为交叉表列字段的问题,所以加上了调整字段顺序的Excel操作。
1s- sSql = "TRANSFORM Sum(A.计次) AS 计次 SELECT A.单位, A.个人编号,A.姓名,Sum(Int((A.人次*1.6-A.金额)/0.8)) AS 分类四," & _
- "Sum(A.人次-Int((A.人次*1.6-A.金额)/0.8)) AS 分类五, Sum(A.金额) AS 金额" & _
- " FROM [CARD_DETAIL$] AS A GROUP BY A.单位, A.个人编号, A.姓名" & _
- " PIVOT IIf(A.证类型='证件七' Or A.证类型='证件八','分类一'," & _
- " IIf(A.证类型='证件一' Or A.证类型='证件五','分类二', " & _
- " IIf(A.证类型='证件三' Or A.证类型='证件九','分类三'))) In ('分类一','分类二','分类三')"
- Set oRs = New ADODB.Recordset
- oRs.Open sSql, oConn, adOpenKeyset, adLockOptimistic
- Sheets("DataGether").Select
- For i = 0 To oRs.Fields.Count - 1
- Cells(1, i + 1) = oRs.Fields(i).Name
- Next
- Range("a2").CopyFromRecordset oRs
- Columns("D:F").Select
- Selection.Cut
- Range("J1").Select
- Selection.Insert Shift:=xlToRight
复制代码
此外,如果用记录集来调整字段位置,则时间较长(在我这里测试是11s),大体代码如下:- Cells(1, 1) = oRs(0).Name
- Cells(1, 2) = oRs(1).Name
- Cells(1, 3) = oRs(2).Name
- Cells(1, 4) = oRs(6).Name
- Cells(1, 5) = oRs(7).Name
- Cells(1, 6) = oRs(8).Name
- Cells(1, 7) = oRs(3).Name
- Cells(1, 8) = oRs(4).Name
- Cells(1, 9) = oRs(5).Name
- For i = 1 To oRs.RecordCount
- Cells(i + 1, 1) = oRs(0)
- Cells(i + 1, 2) = oRs(1)
- Cells(i + 1, 3) = oRs(2)
- Cells(i + 1, 4) = oRs(6)
- Cells(i + 1, 5) = oRs(7)
- Cells(i + 1, 6) = oRs(8)
- Cells(i + 1, 7) = oRs(3)
- Cells(i + 1, 8) = oRs(4)
- Cells(i + 1, 9) = oRs(5)
- oRs.MoveNext
- Next
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|