?
Solved

Access query grid query

Posted on 2016-11-05
10
Medium Priority
?
61 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
[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
  • 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 46

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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 51

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 46

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

762 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