R
RandieRae
Here is my SQL:
SELECT ProductList.ProductID
,ProductList.Score AS Expr1
, ProductList.Ranking
, [Company Info].Company
, ProductList.Product
, ProductList.Purpose
, ProductList.Target
, ProductList.Units
, ProductList.Employment
, ProductList.[Special Notes]
, ProductList.[Select]
FROM [Company Info] INNER JOIN ProductList ON [Company Info].Company =
ProductList.Company
WHERE (((ProductList.Score)<=([Forms]![ClientInfo]![Score]))
AND ((ProductList.Ranking)>=([Forms]![ClientInfo]![Ranking]))
AND ((([ProductList].[Purpose])=[Forms]![ClientInfo]![Purpose] Or
[Forms]![ClientInfo]![Purpose] Is Null)<>False)
AND ((([ProductList].[Target])=[Forms]![ClientInfo]![Target] Or
[Forms]![ClientInfo]![Target] Is Null)<>False)
AND ((([ProductList].[Units])=[Forms]![ClientInfo]![Units] Or
[Forms]![ClientInfo]![Units] Is Null)<>False)
AND ((([ProductList].[Employment])=[Forms]![ClientInfo]![Employment] Or
[Forms]![ClientInfo]![Employment] Is Null)<>False))
OR (((ProductList.Ranking)>=([Forms]![ClientInfo]![Ranking]))
AND ((([ProductList].[Purpose])=[Forms]![ClientInfo]![Purpose] Or
[Forms]![ClientInfo]![Purpose] Is Null)<>False)
AND ((([ProductList].[Target])=[Forms]![ClientInfo]![Target] Or
[Forms]![ClientInfo]![Target] Is Null)<>False)
AND ((([ProductList].[Units])=[Forms]![ClientInfo]![Units] Or
[Forms]![ClientInfo]![Units] Is Null)<>False)
AND ((([ProductList].[Employment])=[Forms]![ClientInfo]![Employment] Or
[Forms]![ClientInfo]![Employment] Is Null)<>False)
AND (([Forms]![ClientInfo]![Score]) Is Null))
OR (((ProductList.Score)<=([Forms]![ClientInfo]![Score]))
AND ((([ProductList].[Purpose])=[Forms]![ClientInfo]![Purpose] Or
[Forms]![ClientInfo]![Purpose] Is Null)<>False)
AND ((([ProductList].[Target])=[Forms]![ClientInfo]![Target] Or
Forms]![ClientInfo]![Target] Is Null)<>False)
AND ((([ProductList].[Units])=[Forms]![ClientInfo]![Units] Or
[Forms]![ClientInfo]![Units] Is Null)<>False) AND
((([ProductList].[Employment])=[Forms]![ClientInfo]![Employment] Or
[Forms]![ClientInfo]![Employment] Is Null)<>False)
AND (([Forms]![ClientInfo]![Ranking]) Is Null))
OR (((([ProductList].[Purpose])=[Forms]![ClientInfo]![Purpose] Or
[Forms]![ClientInfo]![Purpose] Is Null)<>False) AND
((([ProductList].[Target])=[Forms]![ClientInfo]![Target] Or
[Forms]![ClientInfo]![Target] Is Null)<>False)
AND ((([ProductList].[Units])=[Forms]![ClientInfo]![Units] Or
[Forms]![ClientInfo]![Units] Is Null)<>False)
AND ((([ProductList].[Employment])=[Forms]![ClientInfo]![Employment] Or
[Forms]![ClientInfo]![Employment] Is Null)<>False)
AND (([Forms]![ClientInfo]![Score]) Is Null)
AND (([Forms]![ClientInfo]![Ranking]) Is Null))
ORDER BY ProductList.Score DESC , ProductList.Ranking DESC , [Company
Info].Company;
This query works perfectly. But some products have multiple scores, each
record with it's own ProductID. How do I limit the results to the nearest
value to that entered on the form? I've tried using the MAX() function in a
subquery, inserted before the ORDER BY to group by Product, but I keep
getting error messages 3075 and 3071. Can anybody tell me what I'm doing
wrong?
SELECT ProductList.ProductID
,ProductList.Score AS Expr1
, ProductList.Ranking
, [Company Info].Company
, ProductList.Product
, ProductList.Purpose
, ProductList.Target
, ProductList.Units
, ProductList.Employment
, ProductList.[Special Notes]
, ProductList.[Select]
FROM [Company Info] INNER JOIN ProductList ON [Company Info].Company =
ProductList.Company
WHERE (((ProductList.Score)<=([Forms]![ClientInfo]![Score]))
AND ((ProductList.Ranking)>=([Forms]![ClientInfo]![Ranking]))
AND ((([ProductList].[Purpose])=[Forms]![ClientInfo]![Purpose] Or
[Forms]![ClientInfo]![Purpose] Is Null)<>False)
AND ((([ProductList].[Target])=[Forms]![ClientInfo]![Target] Or
[Forms]![ClientInfo]![Target] Is Null)<>False)
AND ((([ProductList].[Units])=[Forms]![ClientInfo]![Units] Or
[Forms]![ClientInfo]![Units] Is Null)<>False)
AND ((([ProductList].[Employment])=[Forms]![ClientInfo]![Employment] Or
[Forms]![ClientInfo]![Employment] Is Null)<>False))
OR (((ProductList.Ranking)>=([Forms]![ClientInfo]![Ranking]))
AND ((([ProductList].[Purpose])=[Forms]![ClientInfo]![Purpose] Or
[Forms]![ClientInfo]![Purpose] Is Null)<>False)
AND ((([ProductList].[Target])=[Forms]![ClientInfo]![Target] Or
[Forms]![ClientInfo]![Target] Is Null)<>False)
AND ((([ProductList].[Units])=[Forms]![ClientInfo]![Units] Or
[Forms]![ClientInfo]![Units] Is Null)<>False)
AND ((([ProductList].[Employment])=[Forms]![ClientInfo]![Employment] Or
[Forms]![ClientInfo]![Employment] Is Null)<>False)
AND (([Forms]![ClientInfo]![Score]) Is Null))
OR (((ProductList.Score)<=([Forms]![ClientInfo]![Score]))
AND ((([ProductList].[Purpose])=[Forms]![ClientInfo]![Purpose] Or
[Forms]![ClientInfo]![Purpose] Is Null)<>False)
AND ((([ProductList].[Target])=[Forms]![ClientInfo]![Target] Or
Forms]![ClientInfo]![Target] Is Null)<>False)
AND ((([ProductList].[Units])=[Forms]![ClientInfo]![Units] Or
[Forms]![ClientInfo]![Units] Is Null)<>False) AND
((([ProductList].[Employment])=[Forms]![ClientInfo]![Employment] Or
[Forms]![ClientInfo]![Employment] Is Null)<>False)
AND (([Forms]![ClientInfo]![Ranking]) Is Null))
OR (((([ProductList].[Purpose])=[Forms]![ClientInfo]![Purpose] Or
[Forms]![ClientInfo]![Purpose] Is Null)<>False) AND
((([ProductList].[Target])=[Forms]![ClientInfo]![Target] Or
[Forms]![ClientInfo]![Target] Is Null)<>False)
AND ((([ProductList].[Units])=[Forms]![ClientInfo]![Units] Or
[Forms]![ClientInfo]![Units] Is Null)<>False)
AND ((([ProductList].[Employment])=[Forms]![ClientInfo]![Employment] Or
[Forms]![ClientInfo]![Employment] Is Null)<>False)
AND (([Forms]![ClientInfo]![Score]) Is Null)
AND (([Forms]![ClientInfo]![Ranking]) Is Null))
ORDER BY ProductList.Score DESC , ProductList.Ranking DESC , [Company
Info].Company;
This query works perfectly. But some products have multiple scores, each
record with it's own ProductID. How do I limit the results to the nearest
value to that entered on the form? I've tried using the MAX() function in a
subquery, inserted before the ORDER BY to group by Product, but I keep
getting error messages 3075 and 3071. Can anybody tell me what I'm doing
wrong?