表A的字段:单号,料号,品名,数量,日期,审核表B的字段:单号,料号,品名,数量,日期,审核,客户
注:
,
2.合并后在,单号,料号,品名,在同一行
'Dim cmd As New SQ-LCommand
'Dim dt As DataTable
'Dim sCols() As String = {"单号", "料号", "品名", "数量", "日期"}
'Dim dCols() As String = {"单号", "料号", "品名", "表A数量", "日期"}
'cmd.C'"
'cmd.CommandText = "SELEC-T * From {表A}WHERE 审核 = '未审核"
'dt = cmd.ExecuteReader()
'For Each dr As DataRow In dt.DataRows
' Dim nr As DataRow = DataTables("员工").AddNew()
' For i As Integer = 0 To sCols.Length - 1
' nr(dCols(i)) = dr(sCols(i))
' Next
'Next
[此贴子已经被作者于2023/8/25 16:51:23编辑过]
如果是SqlServer,直接使用SQL生成表D参考
select
a.单号,a.料号,a.品名,a.数量 as 表A数量,a.日期 as 表A日期,表B数量,表C数量,a.审核 from 表A as a inner join ( select 单号,料号,品名,sum(数量) as 表B数量 from 表B group by 单号,料号,品名) as b on a.单号=b.单号 and a.料号=b.料号 and a.品名=b.品名 inner join ( select 单号,料号,品名,sum(数量) as 表C数量 from 表C group by 单号,料号,品名) as c on a.单号=c.单号 and a.料号=c.料号 and a.品名=c.品名
Dim cmd As New SQ-LCommand
cmd.C'
Dim dt As DataTable
cmd.CommandText = select a.单号,a.料号,a.品名,a.数量 as 表A数量,a.日期 as 表A日期,表B数量,表C数量,a.审核 from 表A as a inner join ( select 单号,料号,品名,sum(数量) as 表B数量 from 表B group by 单号,料号,品名) as b on a.单号=b.单号 and a.料号=b.料号 and a.品名=b.品名 inner join ( select 单号,料号,品名,sum(数量) as 表C数量 from 表C group by 单号,料号,品名) as c on a.单号=c.单号 and a.料号=c.料号 and a.品名=c.品名
Tables("表D").DataSource = cmd.ExecuteReader()
执行报错
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2022.8.18.1
错误所在事件:
详细错误信息:
SELEC-T 子句中包含一个保留字、拼写错误或丢失的参数,或标点符号不正确
[此贴子已经被作者于2023/8/24 11:42:10编辑过]
各种中文的符号改为英文符号,如逗号等改为英文逗号。
另外这种语法适合SqlServer,其它数据库的多表关联用法请自行百度
加到最后面
.........=c.料号 and a.品名=c.品名 where a.审核='未审核'
cmd.CommandText = select a.单号,a.料号,a.品名,a.数量 as 表A数量,a.日期 as 表A日期,表B数量,表C数量,a.审核 from (表A as a inner join ( s
elect 单号,料号,品名,sum(数量) as 表B数量 from 表B group by 单号,料号,品名) as b on a.单号=b.单号 and a.料号=b.料号 and a.品名=b.品名) inner join (
select 单号,料号,品名,sum(数量) as 表C数量 from 表C group by 单号,料号,品名) as c on a.单号=c.单号 and a.料号=c.料号 and a.品名=c.品名 where a.审核='未审核'