Solved

Access 2016 - Query Challenge

Posted on 2016-10-27
15
68 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 35

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 35

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 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 35

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 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