|
楼主 |
发表于 2011-11-19 13:00
|
显示全部楼层
本帖最后由 fsc163198 于 2011-11-19 13:35 编辑
汗! 弄了两天 结果是出来了 还是不理想 请高手指点- Sub SQL计算现库存()
- Dim CNN As New ADODB.Connection
- Dim rs As New ADODB.Recordset
- CNN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName
- strSQL = "SELECT * FROM (SELECT A.颜色,(A.短厚L线-iif(isnull(B.短厚L线),0,B.短厚L线))as 短厚L线,(A.长厚L线-iif(isnull(B.长厚L线),0,B.长厚L线))as 长厚L线,(A.短薄L线-iif(isnull(B.短薄L线),0,B.短薄L线))as 短薄L线,(A.长薄L线-iif(isnull(B.长薄L线),0,B.长薄L线))as 长薄L线 FROM [L线库存运算$A2:E40] AS A Left JOIN [L线库存运算$G2:K40] AS B ON B.颜色=A.颜色) union SELECT * FROM (SELECT B.颜色,(iif(isnull(A.短厚L线),0,A.短厚L线)-B.短厚L线)as 短厚L线,(iif(isnull(A.长厚L线),0,A.长厚L线)-B.长厚L线)as 长厚L线,(iif(isnull(A.短薄L线),0,A.短薄L线)-B.短薄L线)as 短薄L线,(iif(isnull(A.长薄L线),0,A.长薄L线)-B.长薄L线)as 长薄L线 FROM [L线库存运算$A2:E40] AS A RIGHT JOIN [L线库存运算$G2:K40] AS B ON B.颜色=A.颜色)"
- rs.Open (strSQL), CNN, adOpenKeyset, adLockReadOnly
- For Each Field In rs.Fields
- [S2].Offset(0, i) = Field.Name
- i = i + 1
- Next
- Range("S3").CopyFromRecordset rs
- Set rs = Nothing
- Set CNN = Nothing
- End Sub
复制代码 |
|