ed coleman
Registered User.
- Local time
- Yesterday, 16:01
- Joined
- Nov 8, 2012
- Messages
- 44
SELECT DISTINCT tblItemsForMatch.*, Nz([L].[QTY],[H].[QTY]) AS qtyCompare, Nz([L].[Quote_Price],[H].[Quote_Price]) AS QuoteCompare
FROM (tblItemsForMatch LEFT JOIN tblQuoteForPeriod AS L ON tblItemsForMatch.item = L.item) LEFT JOIN tblQuoteForPeriod AS H ON tblItemsForMatch.item = H.item
WHERE (((L.QTY)=(SELECT Max(qty) FROM [tblQuoteForPeriod] WHERE item=[tblItemsForMatch].[item] and qty<=[tblItemsForMatch].[QTY_ORDERED]))) OR ((((SELECT Max(qty) FROM [tblQuoteForPeriod] WHERE item=[tblItemsForMatch].[item] and qty<=[tblItemsForMatch].[QTY_ORDERED])) Is Null) AND ((H.QTY)=(SELECT Min(qty) FROM [tblQuoteForPeriod] WHERE item=[tblItemsForMatch].[item] and qty>[tblItemsForMatch].[QTY_ORDERED])));
SELECT Query1.[item], Query1.[ORDER_NO], Query1.[QTY_ORDERED], Query1.[PRICING_METH], Query1.[ORD_PRICE], Query1.[IHI_PP], Query1.[qtyCompare], Query1.[QuoteCompare]
FROM Query1
WHERE (((Query1.[item]) In (SELECT [item] FROM [Query1] As Tmp GROUP BY [item],[ORDER_NO],[QTY_ORDERED],[PRICING_METH],[ORD_PRICE],[IHI_PP] HAVING Count(*)>1 And [ORDER_NO] = [Query1].[ORDER_NO] And [QTY_ORDERED] = [Query1].[QTY_ORDERED] And [PRICING_METH] = [Query1].[PRICING_METH] And [ORD_PRICE] = [Query1].[ORD_PRICE] And [IHI_PP] = [Query1].[IHI_PP])))
ORDER BY Query1.[item], Query1.[ORDER_NO], Query1.[QTY_ORDERED], Query1.[PRICING_METH], Query1.[ORD_PRICE], Query1.[IHI_PP];
isn't that what you asked for?You've also picked up the lowest quantity on file when the ordered quantity is less than the lowest
use the lowest quantity in the quote file with the corresponding quote price
SELECT tblItemsForMatch.*, Nz([L].[QTY],[H].[QTY]) AS qtyCompare, Nz([L].[Quote_Price],[H].[Quote_Price]) AS QuoteCompare
FROM (tblItemsForMatch LEFT JOIN (SELECT DISTINCT tblItemsForMatch.item, tblItemsForMatch.ORDER_NO, tblItemsForMatch.QTY_ORDERED, L.QTY, L.QUOTE_PRICE
FROM tblItemsForMatch LEFT JOIN tblQuoteForPeriod AS L ON tblItemsForMatch.item = L.item
WHERE (((L.QTY)=(SELECT Max(qty) FROM [tblQuoteForPeriod] WHERE item=[tblItemsForMatch].[item] and qty<=[tblItemsForMatch].[QTY_ORDERED])))) AS L ON (tblItemsForMatch.ORDER_NO = L.ORDER_NO) AND (tblItemsForMatch.item = L.item)) LEFT JOIN (SELECT DISTINCT tblItemsForMatch.item, tblItemsForMatch.ORDER_NO, H.QTY, H.QUOTE_PRICE
FROM tblItemsForMatch LEFT JOIN tblQuoteForPeriod AS H ON tblItemsForMatch.item = H.item
WHERE (((H.QTY)=(SELECT Min(qty) FROM [tblQuoteForPeriod] WHERE item=[tblItemsForMatch].[item] and qty>[tblItemsForMatch].[QTY_ORDERED])))) AS H ON (tblItemsForMatch.ORDER_NO = H.ORDER_NO) AND (tblItemsForMatch.item = H.item)
WHERE (((tblItemsForMatch.item)="Z102823-1--"));