二表SUM后合并,为何得出错误结果?
单表各自求和的结果是正确的,但二表求和后合并的结果是错误的。如下图
请问:
(1)正确的语句是什么?
(2)XP系统下access2000中不支持ISNULL吗?空值处本想显示为“0”,但报错
(3)最想要的full join,但报错的,是VB6不支持的吗?
谢谢!!!
moretable.zip
(16.38 KB)
程序代码:
Dim cn As ADODB.Connection Dim rs1, rs2, rs3 As ADODB.Recordset Private Sub Form_Load() Set cn = New ADODB.Connection cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\rc.mdb" '////////////////////////// Set rs1 = New ADODB.Recordset rs1.Open "select 编号,规格,sum(数量) as 已生产 from sc group by 编号,规格 ", cn, adOpenStatic, adLockOptimistic If rs1.RecordCount > 0 Then Set MSHFlexGrid1.DataSource = rs1 Else Exit Sub End If '/////////////////////////// Set rs2 = New ADODB.Recordset rs2.Open "select 编号,sum(数量) as 已包装 from bz group by 编号 ", cn, adOpenStatic, adLockOptimistic If rs2.RecordCount > 0 Then Set MSHFlexGrid2.DataSource = rs2 Else Exit Sub End If '/////////////////////////// Set rs3 = New ADODB.Recordset rs3.Open "select sc.编号,sc.规格,sum(sc.数量) as 已生产, sum(bz.数量) as 已包装 from sc left join bz on sc.编号=bz.编号 group by sc.编号,sc.规格 ", cn, adOpenStatic, adLockOptimistic If rs3.RecordCount > 0 Then Set MSHFlexGrid3.DataSource = rs3 Else Exit Sub End If rs1.Close rs2.Close rs3.Close cn.Close Set rs1 = Nothing Set rs2 = Nothing Set rs3 = Nothing Set cn = Nothing End Sub
[此贴子已经被作者于2020-8-10 20:36编辑过]