on 2022 May 25 1:53 AM
Hi Team,
I'm trying to identify customers who purchased from one warehouse but not from the other and I have this query, which is working and giving the correct answer but takes nearly 3 minutes to run, even though the timeframe is very short (only two months). Is there a way to simplify this to make the query faster?
Or maybe I'm approaching it completely wrong with the subquery?
Many thanks,
Ildi
SELECT distinct T0.CardCode
FROM OINV T0 INNER JOIN INV1 T1 on T0.DocEntry=T1.DocEntry
WHERE T0.DocDate>='2022-01-01' AND T0.DocDate<='2022-02-28' AND T1.WhsCode='08'
AND T0.CardCode NOT IN (SELECT distinct T0.CardCode
FROM OINV T0 INNER JOIN INV1 T1 on T0.DocEntry=T1.DocEntry
WHERE T0.DocDate>='2022-01-01' AND T0.DocDate<='2022-02-28' AND T1.WhsCode='01')
Request clarification before answering.
Hi,
Try this
SELECT distinct T0.CardCode
FROM OINV T0 WITH(NOLOCK) INNER JOIN INV1 T1 WITH(NOLOCK) on T0.DocEntry=T1.DocEntry
WHERE T0.DocDate>='2022-01-01' AND T0.DocDate<='2022-02-28' AND T1.WhsCode='08'
AND T0.CardCode NOT IN (SELECT distinct T0.CardCode
FROM OINV T0 WITH(NOLOCK) INNER JOIN INV1 T1 WITH(NOLOCK) on T0.DocEntry=T1.DocEntry
WHERE T0.DocDate>='2022-01-01' AND T0.DocDate<='2022-02-28' AND T1.WhsCode='01')Hope this helps,
Son Tran
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 32 | |
| 17 | |
| 16 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.