|
楼主 |
发表于 2011-6-7 22:12
|
显示全部楼层
这是我的代码,使用left outer join和子查询,结果就是不能跑大于65536行的数据。环境是2007sp3
Private Sub connect2databaseGCWTD(ByVal Database As String)
'Sub connect2databaseGCWTD()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String, sql1 As String
Dim i As Long
'MsgBox Replace(Sheet5.Range("B3"), "W", "", 1, 1)
cn.Open " Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Database & ";Extended Properties='Excel 12.0;IMEX=1;HDR=YES';Persist Security Info=True;"
sql1 = "select Inside_ISR_Team as teamName,sum(Rev_Svc) as WTDSum_Rev_Svc,sum(Mgn_Svc) as WTDsum_Mgn_Svc from [Sheet1$] where Fiscal_QuarterWeek=" & CLng(Replace(Sheet5.Range("B3"), "W", "", 1, 1)) & " AND [Region]='" & Sheet5.Range("b2").Value & "'and Inside_ISR_Team in (select [Team] from [" & ThisWorkbook.FullName & "].[Allteam$]) group by Inside_ISR_Team"
sql = "select team,location,WTDSum_Rev_Svc,WTDsum_Mgn_Svc,SUBLOCATION from [" & ThisWorkbook.FullName & "].[Allteam$] a left outer join (" & sql1 & ") b on b.[teamName]=a.[Team];"
rs.Open sql, cn
Sheet6.Cells.ClearContents
Sheet6.Range("a2").CopyFromRecordset rs
For i = 0 To rs.Fields.Count - 1
Sheet6.Cells(1, i + 1) = rs.Fields(i).Name
Next
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub |
|