mshaynerush
Board Regular
- Joined
- Oct 2, 2012
- Messages
- 96
Background:
I have two tables from two different sources. There is no way to combine these two as one is an excel spreadsheet and the other exists as an ODBC on our server.
I could run a query, maybe to combine them into one, but one has maybe 25 rows, the other about 20,000 rows.
I'm not clear on relationships in Access or between tables and how that works yet.
My job involves tracking contractors on various levels, including, failed inspections in the last 30 days for ALL contractors(over 250 of them), total projects submitted, Money paid to each contractor, etc...
most of that I can query from one table, but for one metric, i have a challenge.
In the code below, I can determine which contractors on the Projects Table have had failed inspections in the last 30 days and populate my report with that list of names and how many inspections they failed.
What i need to do is consider another table's data, since this can't be included in my export from the Projects table which is drawn from a program we use for tracking the entire program process for our projects.
so, I have to include inspection results done by a 3rd party, and track those results myself(I use Excel and created a table called VTEAM TRACKING. I want to make one query that will sum all the failed inspections from the Projects table with the failed inspections in the VTEAM table.
On the projects table, i have to find rows that meet the following criteria to determine what a failed inspection is.
Contractor name excluding "TBD" and no Null values + Failed Post-Inspection X 3 or more + On this date >= today -30 days
On my VTEAM table, i have a field that tells me if the inspection failed or not, so in that, i can do a query for
contractor + inspection date >= today - 30 days + inspection failed = "Yes"
My end result needs to be the total failed inspections in the last 30 days for ALL contractors within my tables as one number i can plug into my report ListBox.
Your help is appreciated as I'm still learning this SQL thing.
My Code that works so far:
I have two tables from two different sources. There is no way to combine these two as one is an excel spreadsheet and the other exists as an ODBC on our server.
I could run a query, maybe to combine them into one, but one has maybe 25 rows, the other about 20,000 rows.
I'm not clear on relationships in Access or between tables and how that works yet.
My job involves tracking contractors on various levels, including, failed inspections in the last 30 days for ALL contractors(over 250 of them), total projects submitted, Money paid to each contractor, etc...
most of that I can query from one table, but for one metric, i have a challenge.
In the code below, I can determine which contractors on the Projects Table have had failed inspections in the last 30 days and populate my report with that list of names and how many inspections they failed.
What i need to do is consider another table's data, since this can't be included in my export from the Projects table which is drawn from a program we use for tracking the entire program process for our projects.
so, I have to include inspection results done by a 3rd party, and track those results myself(I use Excel and created a table called VTEAM TRACKING. I want to make one query that will sum all the failed inspections from the Projects table with the failed inspections in the VTEAM table.
On the projects table, i have to find rows that meet the following criteria to determine what a failed inspection is.
Contractor name excluding "TBD" and no Null values + Failed Post-Inspection X 3 or more + On this date >= today -30 days
On my VTEAM table, i have a field that tells me if the inspection failed or not, so in that, i can do a query for
contractor + inspection date >= today - 30 days + inspection failed = "Yes"
My end result needs to be the total failed inspections in the last 30 days for ALL contractors within my tables as one number i can plug into my report ListBox.
Your help is appreciated as I'm still learning this SQL thing.
My Code that works so far:
Code:
SELECT DISTINCT [SBL PROJECTS].CONTRACTOR AS [Contractor Name], Count([SBL PROJECTS].PROJTRACKHISTSTATUS) AS [Total Inspections Failed]
FROM [SBL DETAILS] INNER JOIN [SBL PROJECTS] ON [SBL DETAILS].PROJECTNO = [SBL PROJECTS].PROJECTNO
WHERE ((([SBL PROJECTS].ONTHISDATE)>=Date()-30))
GROUP BY [SBL PROJECTS].CONTRACTOR, [SBL PROJECTS].PROJTRACKHISTSTATUS, [SBL DETAILS].PREINSPECTIONDISP, [SBL DETAILS].POSTINSPECTIONDISP
HAVING ((([SBL PROJECTS].CONTRACTOR)<>"TBD" And ([SBL PROJECTS].CONTRACTOR)<>"In-house" And ([SBL PROJECTS].CONTRACTOR) Is Not Null) AND ((Count([SBL PROJECTS].PROJTRACKHISTSTATUS))>=3) AND (([SBL PROJECTS].PROJTRACKHISTSTATUS)="Failed Post-Inspection"));