Solved

Access query grid query

Posted on 2016-11-05
10
20 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
 

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 39

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

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
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…
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…
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…

746 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

10 Experts available now in Live!

Get 1:1 Help Now