|
楼主 |
发表于 2018-8-6 16:18
|
显示全部楼层
谢谢蓝老师,我又加了一项数据,显示FROM 子句语法错误
Dim cnn As Object
Dim Sql As String
Set cnn = CreateObject("ADODB.CONNECTION")
Worksheets("原膜库存").Range("a4:z10000").ClearContents
cnn.Open "Provider=Microsoft.ACE.OleDb.12.0;Extended Properties='Excel 12.0;HDR=YES'; Data Source=" & ThisWorkbook.FullName
Sql = "select A.日期,A.品名,A.规格,A.批号,A.米数,A.重量,B.米数,B.重量,C.米数,C.重量,D.米数,D.重量,E.米数,E.重量,F.米数,F.重量 from " _
& "((((select 日期,品名,规格,批号,SUM(米数) as 米数,SUM(重量) as 重量 FROM [采购入库表$A2:P] GROUP BY 日期,品名,规格,批号) A " _
& " Left Join " _
& "(SELECT 批号,SUM(米数) as 米数,SUM(重量) as 重量 FROM [工单领料表$A2:P] GROUP BY 批号) B ON A.批号=B.批号) " _
& " Left Join " _
& "(SELECT 批号,SUM(米数) as 米数,SUM(重量) as 重量 FROM [工单退库表$A2:P] GROUP BY 批号) C ON A.批号=C.批号)" _
& " Left Join " _
& " (SELECT 批号,SUM(米数) as 米数,SUM(重量) as 重量 FROM [不良品退库表$A2:P] GROUP BY 批号) D ON A.批号=D.批号)" _
& " Left Join " _
& "(SELECT 批号,SUM(米数) as 米数,SUM(重量) as 重量 FROM [管压退库表$A2:P] GROUP BY 批号) E ON A.批号=E.批号)" _
& " Left Join " _
& "(SELECT 批号,SUM(米数) as 米数,SUM(重量) as 重量 FROM [供应商退货表$A2:P] GROUP BY 批号) F ON A.批号=F.批号"
[A3].CopyFromRecordset cnn.Execute(Sql)
cnn.Close: Set cnn = Nothing |
|