Solved

Access 2016 - Query Challenge

Posted on 2016-10-27
15
62 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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

947 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

20 Experts available now in Live!

Get 1:1 Help Now