0

したがって、2 つのクエリがあります。1 つは現在レポートを作成するクエリで、もう 1 つはレポートにデータを追加するために作成したクエリです。

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

あなたの時間、エネルギー、助けてくれてありがとう!深く感謝します:)

4

2 に答える 2

0
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-11-01' 
ORDER BY
mTo,
transactions.date,
transactions.pCode

union all

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-11-01' 
于 2012-10-31T19:23:33.510 に答える
0

私のコメントによると、を使用する方が簡単かもしれません。UNION ALLまた、ANSI JOIN 構文を使用するように更新しました。

SELECT transactions.date,
    transactions.Pcode,
    transactions.L,
    transactions.iL,  
    transactions.q,
    transactions.mTo,
    'query 1' source
FROM transactions
INNER JOIN productlist
    ON transactions.Pcode=productlist.Pcode 
    AND productlist.client=transactions.client 
WHERE (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 ' 
UNION ALL
SELECT transactions.date,
    transactions.pcode,
    transactions.L,
    transactions.iL,  
    transactions.qty,
    transactions.mTo,
    'query 2' source
FROM transactions
INNER JOIN productlist
    ON transactions.pcode=productlist.pcode 
    AND productlist.client=transactions.client 
INNER JOIN productarchive
    ON ProductArchive.TrID=Transactions.ID
INNER JOIN Shipping
    ON ProductArchive.StID = Shipping.ID
WHERE transactions.mFrom='NotAccepted'
    AND Shipping.SID LIKE 'BAG%'
    AND transactions.Date>= '2012-10-01' 
    AND transactions.Date <= '2012-10-31 11:59:59 PM ' 
于 2012-10-31T19:25:28.570 に答える