我有两张表和列纸,没有关于那篇论文的一些数据。我正在尝试根据纸张编号搜索所有数据。从两个表中。我已成功编写了查询,并且正在成功检索数据。但我注意到了。如果我的paperNo包含零(0),则查询不会搜索该数据。而对于非零包含纸张,它两次检索相同的记录。
我不明白出了什么问题。尝试了一切。
这是我的查询.-
SELECT PaperDate.paperNo,
PaperDate.RAW_PAPER,
PaperDate.EDGE_SEALED,
PaperDate.HYDRO_120,
PaperDate.HYDRO_350,
PaperDate.CATALYST_1ST,
PaperDate.CATALYST_2ND,
PaperDate.SIC_350,
tblThicknessPaperDate.rawThickness,
tblThicknessPaperDate.catThickness,
tblThicknessPaperDate.sicThickness,
tblThicknessPaperDate.rejectedThickness
FROM tblThicknessPaperDate
FULL OUTER JOIN PaperDate ON PaperDate.paperNo =tblThicknessPaperDate.paperNo
WHERE (tblThicknessPaperDate.paperNo = @paperNo)
答案 0 :(得分:1)
我会尝试:
FROM tblThicknessPaperDate
RIGHT JOIN PaperDate ON PaperDate.paperNo =tblThicknessPaperDate.paperNo
WHERE (PaperDate.paperNo = @paperNo)
这两个变化是:交换到右连接,所以即使记录不在tblThicknessPaperDate中,我们仍然会在PaperDate中看到记录。另一个变化是在where子句中使用PapterDate.paperNo。由于tblThicknessPaperDate.paperNo可能为null,因此我们不希望在可以避免的地方使用它。
答案 1 :(得分:1)
SELECT PaperDate.paperNo,
PaperDate.RAW_PAPER,
PaperDate.EDGE_SEALED,
PaperDate.HYDRO_120,
PaperDate.HYDRO_350,
PaperDate.CATALYST_1ST,
PaperDate.CATALYST_2ND,
PaperDate.SIC_350,
tblThicknessPaperDate.rawThickness,
tblThicknessPaperDate.catThickness,
tblThicknessPaperDate.sicThickness,
tblThicknessPaperDate.rejectedThickness
FROM tblThicknessPaperDate
FULL OUTER JOIN PaperDate ON PaperDate.paperNo =tblThicknessPaperDate.paperNo
WHERE (tblThicknessPaperDate.paperNo = @papNo | PaperDate.paperNo = @paperNo)