Solved

Access 2016 - Query Challenge

Posted on 2016-10-27
15
48 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
  • 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 49

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
 
LVL 34

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 34

Expert Comment

by:PatHartman
ID: 41882485
Why is my answer incorrect?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 45

Expert Comment

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

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 34

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now