Access Report from Query inexplicably multiplies columns - ms-access

I have a weird problem. First off, I'm not well versed in Access, but I'm using it for a project to track visibility of log sources and detections and map them to the MITRE ATT&CK Framework. I tables such as Techniques to track the MITRE Techniques, Data_Sources to track the various sources used by those Techniques, and Data_Sources_Coverage that has a visibility ranking for each data source for the company. I have a query built with the below SQL (probably a little messy):
SELECT Technique.Name, Technique.ID, Technique.[Tactic ID], Count(Technique.[Data Sources].Value) AS Technique_Sources, Count(Data_Source_Coverage.[Data Source]) AS Sources_Visible
FROM (Data_Sources INNER JOIN Technique ON Data_Sources.Name = Technique.[Data Sources].Value) INNER JOIN Data_Source_Coverage ON Data_Sources.Name = Data_Source_Coverage.[Data Source]
WHERE (Data_Source_Coverage.Coverage)>0)
GROUP BY Technique.Name, Technique.ID, Technique.[Tactic ID];
The query works great, prints the results as I expect them. However, when I generate a report from that query things go off the rails. The report inexplicably (I did nothing to the data), multiplies the Technique_Sources column by the Sources_Visible column and displays that in the Technique_Sources Column, and then every entry in the Sources_Visible column becomes a '1'. Pics below. Thanks for the help.

Related

Access Query - Syntax error

I have created a database with the intention of allowing analysis of patients blood test results for a certain condition. The query itself is working fine however is unsearchable (in other queries i've generated I've identified this is was because I had spaces in the headings and so removed these)
This query is now duplicating patients for each positive test they have from the selection. This seems to be linked to the .value column as goes away when this is removed however then the query becomes unsearchable using the quick search tool.
Is there any solution to this? I'm using the query wizard to build these. Believe the problem is with the 'OtherImmunology.Value' part
SELECT cci.rq6number,
pi.firstname,
pi.lastname,
pi.nhsnumber,
pi.dob,
Datediff("yyyy", [dob], [initialdiagnosisdate]) AS AgeAtDiagnosis,
pi.gender,
pi.[diagnosis(iapconsensuscriteria)],
cci.initialdiagnosisdate,
cci.steroidtherapy,
cci.responsetosteroids,
cci.igg4level,
cci.[igg4actualresult(mg/dl)],
cci.serumigg,
cci.[serumigg result(g/l)],
cci.otherimmunologytested,
cci.otherimmunology,
cci.** otherimmunology.VALUE,
cci **.[ca19-9level],
cci.[ca19-9actualresult(ku/l)],
cci.surgery,
cci.otherautoimmuneconditions,
cci.autoimmunecondition,
cci.completed
FROM [patient information] As pi
INNER JOIN [Clinical Contact Informtion] As cci
ON pi.[rq6number] = cci.[rq6number];

Access 'No Records Found' when Records Exist

I have a form in Access 2010 that's used as a search form to filter records matching specific criteria.
I transferred information in the backend from one set of tables to another. Now, the filter doesn't work. Even if I leave all the criteria blank - ie. set it to bring up all records - it tells me, 'No records found.'
I've remapped the tables a few times, made sure they all have information, and are linking and opening properly. What could be preventing Access from finding the records?
Here's the filter query, if it helps any. It doesn't appear to be filtering properly, even though it works fine with the old tables.
SELECT Activity.*, ActivityCash.*, EngSchDates.*, Monitoring.*, Procurement.*,
LookupDistrict.*
FROM ((((Activity LEFT JOIN LookupDistrict ON Activity.District =
LookupDistrict.District) INNER JOIN ActivityCash ON Activity.GWP = ActivityCash.GWP)
INNER JOIN EngSchDates ON Activity.GWP = EngSchDates.GWP)
INNER JOIN Procurement ON Activity.GWP = Procurement.GWP) INNER JOIN Monitoring ON
Activity.GWP = Monitoring.GWP ORDER BY Activity.District,
Activity.[ProgramYear], [Activity].GWP;
In general, to debug these types of problems, try removing one table at a time from the FROM clause (and SELECT) until you get your results back.
Remove AND [Activity].[Designer] like '*' from the query.

Combining a TRANSFORM......PIVOT and a UNION Query

it's my first time posting here but this site has supplied me with lots of answers in the past so I'll give it a try.
Background information: I'm using Acces 2013, connecting to a MySQL database through ODBC 3.51.
I'm busy pulling reports out of a Call Detail record, namely I want to make an overview of the times different employees have spent receiving and making outgoing calls on different phone lines.
I have already found out I can't make two seperate TRANSFORM...PIVOT query's and UNION those. That makes sense, because there's no way the code knows my 2 query's will return the same amount of Pivots.
Is it possible to turn this process around? (First collect the data you need in a UNION, and then transforming the data).
I created the following Union query collecting the relevant data:
(SELECT dbo_IpPbxCDR.DestinationName AS [Name], Sum(DateDiff('n',[dbo_IpPbxCDR.starttime],[dbo_IpPbxCDR.endtime])) AS [Called Time], IIf((dbo_IpPbxCDR.CalledName Like "*0900*") OR (dbo_IpPbxCDR_1.CalledName like "*0900*"), "0900", "abo") AS [Called Line]
FROM (dbo_IpPbxCDR AS dbo_IpPbxCDR_1 RIGHT JOIN dbo_IpPbxCDR ON dbo_IpPbxCDR_1.CallId = dbo_IpPbxCDR.TransferredCallId2)
WHERE <Where clause relevant to the data I want. It’s pretty long so I omitted it>
GROUP BY dbo_IpPbxCDR.DestinationName, IIf((dbo_IpPbxCDR.CalledName Like "*0900*") OR (dbo_IpPbxCDR_1.CalledName like "*0900*"), "0900", "abo"))
UNION
(SELECT dbo_IpPbxCDR.OriginationName AS [Name], Sum(DateDiff('n',[dbo_IpPbxCDR.starttime],[dbo_IpPbxCDR.endtime])) AS [Called Time], 'uit' AS [Called Line]
FROM dbo_IpPbxCDR
WHERE <Where clause relevant to the data I want. It’s pretty long so I omitted it>
GROUP BY dbo_IpPbxCDR.OriginationName)
I'm trying to transform on Sum(DateDiff('n',[dbo_IpPbxCDR.starttime],[dbo_IpPbxCDR.endtime])) so I can get data relevant to certain months with pivot Month([dbo_IpPbxCDR.starttime])
I'd appreciate any help/advice I can get!

What's a good pattern to implement running queries on individual entities from a obtained result set in Datanucleus/JPA

I am basically obtaining a decently sized result set (a few thousand) through datanucleus by running a JPQL query. On each of these, I also want to find the number of references from another table. The data is in a MySQL db.
For example:
List<Instrument> instruments = em().createQuery("SELECT i FROM Instrument AS i").getResultList();
for(Instrument i : instruments)
{
Query q = em().createQuery("SELECT COUNT(c) FROM Component AS c WHERE c.instrument.id = :id")
q.setParameter("id", i.getId());
long count = (Long) q.getSingleResult();
}
So, basically I want the list of instruments and also the list of components attached to the instrument as per the above example.
I've used similar code at a bunch of places and it performs pretty poorly. I understand that for 2000 instruments, I'll fire 2000 additional queries to count components and that will slow things down. I'm sure there's a better pattern to obtain the same result that I want. How can I get things to speed up?
That's right, this is not an optimal solution. But the good news is that all of this can be done with one or at most two queries.
For instance you don't have to execute the counting query once for each instrument.
You can use grouping and get all counts with one query:
List<Instrument> instruments = em().createQuery("SELECT i FROM Instrument AS i").getResultList();
Query q = em().createQuery("SELECT c.instrument.id, COUNT(c) FROM Component AS c GROUP BY c.instrument.id")
List<Object[]> counts = q.getResultList();
for (Object[] elem : counts) {
// do something
// elem[0] is instrument ID
// elem[1] is count
}
I haven't check that but you can probably also do everything with one query by putting the second query as a subquery in the first one:
SELECT i
(SELECT COUNT(c) FROM Component AS c WHERE c.instrument.id = i.id)
FROM Instrument AS i
Similar to the first example, result list elem[0] would be an Instrument and elem[1] the count. It can be less efficient because the DB will have to execute the subquery for each instrument anyway, but it will be still quicker than your code, because it happens fully on DB side (no round-trips to DB for each counting query).

inner query of subqery returning multiple rows

I am not that experience in sql so please forgive if its not a good question to ask,but i researched around almost for 3-4 days but no able to solve.
My problem is i have a table which have multiple image names in it,so what i have to do is whoever is the follower of a particular user i have to get the imaged from this table,so one user there can be multiple followers,so i have to fetch the images posted by all the followers.
Here is the subquery code snippet i am using.
SELECT id,
outfit_image,
img_title,
description
FROM outfitpic_list r2
WHERE Email=ANY(SELECT being_followed
FROM follower_table
WHERE follower='test#gmail.com')
So the inner query here returns multiple values,for each value(being_followed) i have to fetch all the images and display it,but with this query each time i get only one image.I tried IN also but didnot work out.
Table structure:-
Outfitpic_list table
id|outfit_image|datetime|Email|image_title|description
Follower_table
bring_followed|follower
Please help,I am stuck..!!
Thank you..!!
I think your problem may be the = sign between "E-mail" and "Any". Try this statement:
SELECT
id,
outfit_image,
img_title,
description
FROM outfitpic_list r2
WHERE Email IN
(
SELECT being_followed
FROM follower_table
WHERE follower='test#gmail.com'
)
It's the same statement, without the = sign, and the ANY keyword replaced with IN. (I cleaned it up a little to make it more readable)