SQL解决方案:
- StrSQL = ""
- StrSQL = StrSQL & "SELECT A.[工单号],A.[成品料号],A.[序号],A.[下层物料料号],A.[描述]"
- StrSQL = StrSQL & ",B.[报价用量],B.[报价单价],B.[报价金额]"
- StrSQL = StrSQL & ",B.[生产用量],B.[生产单价],B.[生产金额]"
- StrSQL = StrSQL & ",IIF(B.[报价用量]=B.[生产用量],'OK',IIF(B.[报价用量]=0,'报价BOM没有',IIF(B.[生产用量]=0,'生产BOM没有','不一样'))) AS 结果A"
-
- StrSQL = StrSQL & " FROM ("
-
- StrSQL = StrSQL & "SELECT MAX([工单号]) AS [工单号],[成品料号],[序号],[下层物料料号],[描述]"
- StrSQL = StrSQL & " FROM ("
- StrSQL = StrSQL & "SELECT DISTINCT NULL AS [工单号],[成品料号],[序号],[下层物料料号],[描述]"
- StrSQL = StrSQL & " FROM [" & SH0.Name & "$]"
- StrSQL = StrSQL & " UNION ALL "
- StrSQL = StrSQL & "SELECT DISTINCT [工单号],[成品料号],[序号],[下层物料料号],[描述]"
- StrSQL = StrSQL & " FROM [" & SH1.Name & "$]"
- StrSQL = StrSQL & ") GROUP BY [成品料号],[序号],[下层物料料号],[描述]"
-
- StrSQL = StrSQL & ") AS A LEFT JOIN ( "
- StrSQL = StrSQL & "SELECT [成品料号],[序号],[下层物料料号],[描述]"
- StrSQL = StrSQL & ",SUM([报价用量]) AS [报价用量],MAX([报价单价]) AS [报价单价],SUM([报价金额]) AS [报价金额]"
- StrSQL = StrSQL & ",SUM([生产用量]) AS [生产用量],MAX([生产单价]) AS [生产单价],SUM([生产金额]) AS [生产金额]"
- StrSQL = StrSQL & " FROM ("
- StrSQL = StrSQL & "SELECT [成品料号],[序号],[下层物料料号],[描述]"
- StrSQL = StrSQL & ",[用量] AS [报价用量],[单价] AS [报价单价],[金额] AS [报价金额]"
- StrSQL = StrSQL & ",0 AS [生产用量],0 AS [生产单价],0 AS [生产金额]"
- StrSQL = StrSQL & " FROM [" & SH0.Name & "$]"
- StrSQL = StrSQL & " UNION ALL "
- StrSQL = StrSQL & "SELECT [成品料号],[序号],[下层物料料号],[描述]"
- StrSQL = StrSQL & ",0 AS [报价用量],0 AS [报价单价],0 AS [报价金额]"
- StrSQL = StrSQL & ",[用量] AS [生产用量],[单价] AS [生产单价],[金额] AS [生产金额]"
- StrSQL = StrSQL & " FROM [" & SH1.Name & "$]"
- StrSQL = StrSQL & ") GROUP BY [成品料号],[序号],[下层物料料号],[描述]"
-
- StrSQL = StrSQL & ") AS B ON A.[成品料号]=B.[成品料号] AND A.[下层物料料号]=B.[下层物料料号]"
复制代码 |