我请求一些帮助。我只使用ms访问并开始使用SQL我有两个视图part1和part2我无法加入它们并得到任何结果(我有MS访问的结果(见下面的结果部分)。我需要相同的结果显示在SQL) 谢谢..
查看(第1部分)
select Mvpr.Prefix, Mvpr.SubKey1 AS [Parkers Part Number], Mvpr.SubKey2 AS [Supplier Code], Mvpr.A12 AS [Supplier Part Number], vwProduct.Psupp as part1
FROM vwProduct INNER JOIN Mvpr ON vwProduct.KeyCode = Mvpr.SubKey1
WHERE Mvpr.Prefix ='c'
查看(第2部分)
SELECT dbo.RHeads.Document, RLines.Part, RHeads.Supp, RHeads.[DateTime], RLines.Unit, RLines.CQty, RLines.ClCost, RHeads.POrder, RHeads.Corder, RHeads.Branch as part2
FROM RHeads INNER JOIN RLines ON RHeads.Document = RLines.Document
WHERE RHeads.[DateTime] >= DATEADD(MONTH, -3, GETDATE())
结果
SELECT part1.Document, part1.Part [Parkers Part], part2.[Supplier Part Number], part1.Supp [Supplier Code], part1.Unit [Unit Price], part1.CQty [Qty Recieved], dbo.vwProduct.SI18 Surcharge, part1.POrder, part1.Corder, part1.Branch, part1.DateTime
FROM dbo.vwProduct INNER JOIN part2 INNER JOIN part1 ON part2.[Supplier Code] = part1.Supp AND part2.[Parkers Part Number] = part1.Part ON dbo.vwProduct.KeyCode = part1.Part
GROUP BY part1.Document, part1.Part, part2.[Supplier Part Number], part1.Supp, part1.Unit, part1.CQty, dbo.vwProduct.SI18, part1.POrder, part1.Corder, part1.Branch, part1.DateTime
答案 0 :(得分:0)
根据您在结果中的SQL部分,您的视图(第2部分)应该是您的第1部分,因为文档,部件等列来自该部分,反之亦然。
SELECT part1.Document,
part1.Part [Parkers Part],
part2.[Supplier Part Number],
part1.Supp [Supplier Code],
part1.Unit [Unit Price],
part1.CQty [Qty Recieved],
dbo.vwProduct.SI18 Surcharge,
part1.POrder,
part1.Corder,
part1.Branch,
part1.DateTime
FROM dbo.vwProduct
INNER JOIN part1
ON dbo.vwProduct.KeyCode = part1.Part
INNER JOIN part2
ON part2.[Supplier Code] = part1.Supp
AND part2.[Parkers Part Number] = part1.Part
GROUP BY part1.Document,
part1.Part,
part2.[Supplier Part Number],
part1.Supp,
part1.Unit,
part1.CQty,
dbo.vwProduct.SI18,
part1.POrder,
part1.Corder,
part1.Branch,
part1.DateTime