因此,我有两个查询 - 一个当前创建报告,另一个查询是我编写的用于将更多数据附加到报告中。
我想合并新查询,以便当我在 ASP 中调用它时数据显示在同一数据集中。
我在放置新的 where 子句时遇到了麻烦,以便它只给我想要的东西。这些查询可以自行工作,但我似乎无法弄清楚如何在不给我大量我不想要的额外数据的情况下将它们组合在一起。
这是原始查询:
SELECT
transactions.date,
transactions.Pcode,
transactions.L,
transactions.iL,
transactions.q,
transactions.mTo
FROM
transactions,
productlist
WHERE
transactions.Pcode=productlist.Pcode
AND productlist.client=transactions.client
AND (transactions.mTo='NotAccepted' OR transactions.mTo = 'TheStage')
AND transactions.client=232 AND ( tophysical = 'Place1' OR fromphysical = 'Place1' )
AND transactions.Date>= '2012-10-01'
AND transactions.Date <= '2012-10-31 11:59:59 PM '
ORDER BY
mTo,
transactions.date,
transactions.pCode
我要集成的查询是:
SELECT
transactions.date,
transactions.pcode,
transactions.L,
transactions.iL,
transactions.qty,
transactions.mTo,
FROM
transactions,
productlist,
productarchive,
Shipping
WHERE
transactions.pcode=productlist.pcode
AND productlist.client=transactions.client
AND transactions.mFrom='NotAccepted'
AND ProductArchive.TrID=Transactions.ID
AND ProductArchive.StID = Shipping.ID
AND Shipping.SID LIKE 'BAG%'
AND transactions.Date>= '2012-10-01'
AND transactions.Date <= '2012-10-31 11:59:59 PM '
我想出的最终查询给了我比我想要的多万条记录。
SELECT
transactions.date,
transactions.pCode,
transactions.L,
transactions.iL,
transactions.q,
transactions.mTo
FROM
transactions,
productlist,
shipping,
ProductArchive
WHERE
transactions.pCode=productlist.pCode
AND productlist.client=transactions.client
AND (transactions.mTo='NotAccepted' OR transactions.mTo = 'TheStage' OR transactions.mFrom='NotAccepted')
AND transactions.client=232
AND
( tophysical = 'Place1' OR fromphysical = 'Place1' OR
( ProductArchive.TransID=Transactions.ID
AND ProductArchive.StID = Shipping.ID
AND Shipping.SID LIKE 'BAG%')
)
AND transactions.Date>= '2012-10-01'
AND transactions.Date <= '2012-10-31 11:59:59 PM '
ORDER BY
transactions.mTo,
transactions.date,
transactions.pCode
感谢您的时间、精力和帮助!深表感谢:)