Solved

Access query grid query

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

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

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…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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…
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…

914 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

17 Experts available now in Live!

Get 1:1 Help Now