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
Solved

Access query grid query

Posted on 2016-11-05
10
39 Views
Last Modified: 2016-11-05
I have a query which delivers the data but i dont know how to make the query so that where the cc has slight variants i.e 2401 vs 2400 that I only get 1 value returned. my variance is 5.

I know how to calculate if the variance is in range ie abs x-y >=5

I dont know how to get the grouping correct with this data I would like it to show (here i manually filtered 1 of the 2 out)

this way I get the cc's for the xc90 vor vehicle.

ClientName      CC      StrLink
Abi      2400      XC90 VOR******   or it could show the 2401 and not the 2400
Abi      2521      XC90 VOR
Abi      2922      XC90 VOR
Abi      3192      XC90 VOR
Abi      4414      XC90 VOR
Cap            XC90 VOR
Glass      2400      XC90 VOR
Glass      2521      XC90 VOR
Glass      2922      XC90 VOR
Glass      3192      XC90 VOR
Smmt      2521      XC90 VOR
Smmt      2922      XC90 VOR
Smmt      3192      XC90 VOR
Tvi      0      XC90 VOR





output currently
SELECT QryXC90.ClientName, QryXC90.CC, QryXC90.StrLink
FROM QryXC90
GROUP BY QryXC90.ClientName, QryXC90.CC, QryXC90.StrLink
HAVING (((QryXC90.StrLink)="XC90 VOR"));

Open in new window

0
Comment
Question by:PeterBaileyUk
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 41875217
Show the input data, and the required output.
If possible upload a sample database.
0
 

Author Comment

by:PeterBaileyUk
ID: 41875292
Ive attached a small db qrygroupcc so dont open with your mobile.if you look at client name abi or glass it each has 2 cc value one of 2401 and other 2400.

an ideal query should show but without changing the client data field

ClientName      CC      StrLink
Abi      2400      XC90 VOR
ee.mdb
0
 
LVL 45

Expert Comment

by:aikimark
ID: 41875309
if your variance is 5 or less then you will need something like this:
(Abs(CC - 2400) <= 5)
0
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.

 

Author Comment

by:PeterBaileyUk
ID: 41875317
Variance wasnt the question I want 2400 and 2401 to be grouped together as one. I think it needs a query in a query to group on the min values but not sure.
0
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 41875333
You can also round cc value with function like this:
Public Function round_cc(CC As Variant) As Variant
Dim i As Double
If IsNull(CC) Then
    round_cc = Null
Else
    i = CC / 10
    round_cc = CLng(i) * 10
End If
End Function

Open in new window

0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41875347
You could modify like this to round down by variance:

SELECT 
    QryXC90.ClientName, 
    Int([CC]/20)*20 AS CCGroup, 
    QryXC90.StrLink
FROM 
    QryXC90
GROUP BY 
    QryXC90.ClientName, 
    Int([CC]/20)*20, 
    QryXC90.StrLink
HAVING 
    QryXC90.StrLink="XC90 VOR";

Open in new window

/gustav
0
 
LVL 30

Expert Comment

by:hnasr
ID: 41875465
Try this, run Qery1
SELECT QryXC90.ClientName, QryXC90.StrLink, Min(QryXC90.CC) AS MinOfCC
FROM QryXC90
GROUP BY QryXC90.ClientName, QryXC90.StrLink, Left([CC]+5,Len([CC])-1)
HAVING (((QryXC90.ClientName)="ABI") AND ((QryXC90.StrLink)="XC90 VOR"));

Open in new window

Modify criteria if needed.
ee-2.mdb
0
 
LVL 45

Expert Comment

by:aikimark
ID: 41875485
@PeterBaileyUk

We've been looking at your singular example of 2400 and 2401.  Since you've stated that you need a "variance of 5", does that mean you will accept any value between -5 and +5 of 2400 (or whatever the CC value)?

if so, try the following variation on your original query.  I am assuming that you have some other table (called CCtable in the example) that contains other values that might be eligible.
SELECT QryXC90.ClientName, QryXC90.CC, QryXC90.StrLink
FROM QryXC90 Inner Join CCtable On thejoiningcriteria
WHERE (QryXC90.StrLink="XC90 VOR")
And CCtable.CC Between QryXC90.CC-5 and QryXC90.CC+5
GROUP BY QryXC90.ClientName, QryXC90.CC, QryXC90.StrLink

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 41875509
yes exactly that, that was this example.
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 41875513
thank you.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Access to CSV file from VBA 3 26
Run Stored Procedure uisng ADO 5 21
Access Schema 6 26
How search for records based on a specified date range 14 17
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

838 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