Solved

Access 2016 - Query Challenge

Posted on 2016-10-27
15
84 Views
Last Modified: 2016-11-28
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]));
0
Comment
Question by:DGWhittaker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
15 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 250 total points
ID: 41862167
it isn't behaving
We could use some clarifying details
0
 
LVL 50

Assisted Solution

by:Gustav Brock
Gustav Brock earned 125 total points
ID: 41862177
Most likely you may, in the query, have to specify these:

    [Forms]![LaunchPad]![StartDate]
    [Forms]![LaunchPad]![End Date]

as parameters of data type Date.

/gustav
0
 

Author Comment

by:DGWhittaker
ID: 41862368
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
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 37

Assisted Solution

by:PatHartman
PatHartman earned 125 total points
ID: 41862550
The HAVING Clause should be a WHERE clause

The HAVING clause is applied AFTER aggregation and should only be used on aggregated values.  The WHERE is applied prior to aggregation and is used to eliminate or select items to aggregate.  Store_ID isn't in the selected columns so it is gone after aggregation and that is why the query fails to return anything.
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 41882485
Why is my answer incorrect?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 41882521
I think PatHartman posted the best answer
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 41882888
Without a response, no one knows, an no reply will be of interest or knowledge for upcoming readers. Thus a delete.

/gustav
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 41882968
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.
0
 

Author Comment

by:DGWhittaker
ID: 41883031
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
0
 

Author Comment

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

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question