Link to home
Start Free TrialLog in
Avatar of DGWhittaker
DGWhittaker

asked on

Access 2016 - Query Challenge

Greetings!
I have a query that needs to pull certain data from a form, however it isn't behaving.
Please review this SQL code and let me know if you see where I went sideways,
thanks!
Dennis

SELECT DISTINCTROW tbl_entry_sheet.team_leader, ([first_name] & " " & [last_name]) AS Sales, tbl_entry_sheet.deal_num, tbl_entry_sheet.total_est_feg, Avg(tbl_entry_sheet.days_in_stock) AS AvgOfdays_in_stock, Avg(tbl_entry_sheet.billed_beg) AS AvgOfbilled_beg, Avg(tbl_entry_sheet.ptoc) AS AvgOfptoc, 1 AS CountOfsalesman_id1, tbl_entry_sheet.deal_type, [total_est_feg]+[billed_beg]+[ptoc] AS Contribution, Count(tbl_entry_sheet.customer) AS CountOfcustomer, tbl_entry_sheet.dealdate, tbl_entry_sheet.dealdate, [billed_beg]+[ptoc] AS ["BEG+BS"], tbl_entry_sheet.deal_type, tbl_entry_sheet.tint_amt, tbl_entry_sheet.tint, GunnDealershipData.Logo
FROM tbl_new_vehicles, (tbl_entry_sheet INNER JOIN tbl_salesmen ON tbl_entry_sheet.salesman_id1 = tbl_salesmen.salesman_id) INNER JOIN GunnDealershipData ON tbl_entry_sheet.store_id = GunnDealershipData.[Store#]
GROUP BY tbl_entry_sheet.team_leader, ([first_name] & " " & [last_name]), tbl_entry_sheet.deal_num, tbl_entry_sheet.total_est_feg, [total_est_feg]+[billed_beg]+[ptoc], tbl_entry_sheet.dealdate, [billed_beg]+[ptoc], tbl_entry_sheet.deal_type, tbl_entry_sheet.tint_amt, tbl_entry_sheet.tint, tbl_entry_sheet.store_id, tbl_entry_sheet.deal_type, tbl_entry_sheet.dealdate, tbl_entry_sheet.dealdate
HAVING (((tbl_entry_sheet.store_id)=[Forms]![LaunchPad]![Dealership]) AND ((tbl_entry_sheet.deal_type)>=[Forms]![LaunchPad]![StartDate]) AND ((tbl_entry_sheet.dealdate)<=[Forms]![LaunchPad]![End Date]));
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DGWhittaker
DGWhittaker

ASKER

I will try the date parameter to see if that fixes it.

When I run the query it comes up empty even though there is data in the form to filter the data by dealership, start and end date.

Hope that helps!
Thanks all!
Dennis
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why is my answer incorrect?
I think PatHartman posted the best answer
Without a response, no one knows, an no reply will be of interest or knowledge for upcoming readers. Thus a delete.

/gustav
As I look at again, the second condition is most likely the issue.

 ((tbl_entry_sheet.deal_type)>=[Forms]![LaunchPad]![StartDate])

deal_type should probably be dealdate.

However, the use of HAVING is still incorrect.  It is just not causing this problem.
Greetings All!
Sorry to have caused a concern.
In the end this was a nonsensical issue where I was calling the field name instead of the field. The original code worked fine.

I want to make sure everyone gets recognized for their efforts, so should I simply give everyone some credit?

Thanks!
Dennis
I have closed this question at least 2 times already.
I don't know why it still pops up,
Thanks!
Dennis