I have a query with a record id, report date and status.
How do I pull the latest record if the status is AA?
For latest record in report date I used Max in Totals. With just this max it is pulling the latest date for each set of records with the same record id.
This is a start now how do i pull the latest record that has a AA status?
(1) a query that returns the latest record (newest) in a table called 'Invoices' and then
(2) places this value in a form called 'FrmInputInvoices' as the default value when the form opens. Newest record is by Autonumber and the table defaults this to top of table as views newest down to oldest.
Re (1) Query is called 'QInvoices'; the values I want to return in my query is ID (my autonumber) and Invoice_No . Must be a simple answer to put in the criteria, but I can't find this.
Re(2) What code do I use in my Form field named 'Invoice_No when the curser defaults there on opening?
I would like to write a ms-sql query to return the records of each customer number with the latest OrderDate. One more thing, if the customer has two separate order numbers on the same date(should be the latest date), the query should be able to pull up both the records.
I tried with the code below but its taking a long time to execute and finally hanging up MS ACCESS.
SELECT * FROM TableName AS a WHERE Not Exists (SELECT * FROM TableName b WHERE b.CUSTNo = a.CUSTNo AND b.OrderDate >= a.OrderDate);
I have a table that contains readings from several pieces of equipment as well as the status of each one. Each record has a timestamp, equipment number, status, etc. What I want is to create a query that will return the latest record for each equipment number. Simplified example table:
There are more than 20 different Equipment numbers and they are read several times per day and sometimes some of them get missed. What I'm looking for is a way to get a list of all the machines with their latest reading so they can tell which machines are running and which are down based on the last time they were read (instead of specifying a date). I can get this for one machine with no problem. I'm having trouble getting it for more than one machine. I tried a union query (with just 2 of the machines included for testing) but it only returns the results from one machine:
Code:
SELECT TOP 1 TestCompressorRoundQuery.LoggedAt, TestCompressorRoundQuery.AssetNumber, TestCompressorRoundQuery.CompressorID, TestCompressorRoundQuery.Status, TestCompressorRoundQuery.CompressorIntegrity, TestCompressorRoundQuery.Notes FROM TestCompressorRoundQuery WHERE (((TestCompressorRoundQuery.AssetNumber)="104399")) UNION ALL
[Code] ....
I'd rather not have to create a seperate query for each machine and then join all of those together! I think perhaps a Union query might not be the correct approach. All the data is coming from only one table.
If I have four date Fields in a query, Astart, Bstart, Cstart, and Dstart and want to have a calculated field to find the latest date for each record how would I do that? I have tried things like:
I have a table of accounts and a table of rates. There is a one-to-many relationship between them (i.e. each account can have multiple rates, each with their own - unique - effective date)
I'm trying to build a query which will show me all of the accounts in the accounts table and the most recent rate (based on the effective date) for each of those accounts.
This is as far as I've gotten with the SQL :
Code: SELECT [tblAccounts].[AccountID], [tblAccounts].[AccountNumber], [tblAccounts].[AccountName], [LatestRate].[IntRate], [LatestRate].[EffectiveDate] FROM [tblAccounts] LEFT JOIN (SELECT TOP 1 [tblRates].[AccountID], [tblRates].[IntRate], [tblRates].[EffectiveDate] FROM [tblRates] ORDER BY [tblRates].[EffectiveDate] DESC) AS LatestRate ON [tblAccounts].[AccountID] = [LatestRate].[AccountID]
But this can't work because the [LatestRate] subquery can only ever return one record (i.e. the most recent rate across all of the accounts)
I need the most recent rate for each of the accounts in the main query
(FYI - I use an outer join as it is possible for no rate to be available in the rates table for a given account, in which case I want to return the null value rather than omit the account from the resulting dataset...)
Hi All, I am looking for some help with a project I am working on where I need to automatically print a report from my database every time a new record is added to the table. The table contains 13 fields and the report needs to display 12 of them, the other being the index which is set to Autonumber.
The table is being updated solely by ODBC, this is working OK.
There is the potential for records to be added to the table very quickly via the ODBC link, so I need to safeguard that the report is being populated with correct information from the record that triggered the print event. Also, should multiple records be added in close succession, a report needs to be correctly generated/printed for each of one. The DB is to have no user intervention, and will just run on the PC at startup with all access menus/controls locked out.
Any information on how you think I should structure this, or any examples of helpful code that you might have would be very much appreciated.
I am trying to create a query or series of queries that will identify the latest record of a field called CheckInDate. The table will have multiple entries. For example.
Book#__________CheckOutDate_____________CheckInDat e __1_____________01/01/2007_______________03/01/2007 __1_____________04/01/2007_______________05/01/2007 __1_____________01/01/2007_______________ __2_____________01/01/2007_______________02/01/2007 __2_____________02/05/2007_______________04/27/2007 __3_____________01/01/2007_______________03/01/2007 __3_____________05/01/2007_______________07/01/2007
I need the results to be: #1(ALL) will not be listed, as there is a book still checked out #2 will show the record with the 04/27/2007(ONLY), as I want the last time the book was checked out. #3 will show the record with the 07/01/2007(ONLY), as I want the last time the book was checked out.
I currently have a somewhat flat table where this is concerned. Please advise on what I would need to do to create this. Thanks!
I'm fairly new to SQL and have a problem finding the latest record.
Lets say I have a development project that has many disbursal payments to be sent. I want to find the latest disbursal record created for that one project instead of having all of the disbursal records show on the query.
I'm trying to work out how to do this in a query but haven't got a clue where to start.
Please, if anyone can help I'd be very grateful!:D
I am trying to run a Query that searches for a single Tool ID Number and returns the transaction record that has the latest date. My query currently is this:
SELECT LocationStatus.ToolID, LocationStatus.CurrentLocation, LocationStatus.DateofEvent FROM LocationStatus WHERE (((LocationStatus.DateofEvent)=(SELECT MAX(dateofevent) FROM [LocationStatus] AS t2 WHERE t2.[ToolID] = [Tool Number])));
But the problem I am having is that the query is returning MULTIPLE Tool ID numbers with matching dates. Before the query runs a parameter box pops up asking for a Tool ID number but there should only be one record returning. HELP!!!:confused::confused:
I am trying to pick the latest record from "tblEmpVac.id" field but I keep getting syntax errors. I am thinking if the "tblEmpVac.id" = Count('tblEmpVac.id') then that will show the most current record as it will count and match the last record correct?
Another problem is if I put it into the WHERE section, it will give a conflict. So I don't know where to put it. Below is the SQL, if anyone can help it would be great.
SELECT DISTINCTROW tblEmp.position, tblEmp.fname, tblEmp.lname, tblEmpWorkHistory.region, tblEmpWorkHistory.[current store], tblEmpVac.current_year, tblEmpVac.id, tblEmpVac.entitlement, tblEmpVac.days_taken, tblEmpVac.days_carryover, [days_carryover]+[entitlement]-[days_taken] AS total FROM ((tblEmp INNER JOIN tblEmpVac ON tblEmp.ssn = tblEmpVac.ssn) INNER JOIN tblEmpWorkHistory ON tblEmp.ssn = tblEmpWorkHistory.ssn) INNER JOIN tblEmpWorkHistoryData ON tblEmpWorkHistory.ewh_id = tblEmpWorkHistoryData.ewh_id WHERE (((tblEmp.position)<>"Terminated") AND ((tblEmpVac.current_year)="2005")) ORDER BY tblEmp.position, tblEmpWorkHistory.region, tblEmpVac.id;
Where Status 1 = Open, 2 = Allocated and 3 = Closed. ---------------------------------------------------------------------------------------------- I want to get the count of number of queries which are not closed (outstanding) at any point in time.
Example: (with a time parameter) Input | Result 22/10/2007 17:00 | 1 22/10/2007 16:05 | 0 22/10/2007 14:00 | 2
I want to achieve this with just 1 query (not by using one query within the other) b,coz I want to further use this query from Excel VBA (write through Excel VBA and not store the query within Access)
just wondering if it was possible to have a box that returns the % completion of the current record depending on how much data/how many of the fields of the record have been filled out.
e.g. fields with containing data / total number of fields * 100
I have a database which contains a field 'status'. This status takes a numerical value (1, 2, 3, etc...). Everything works great.
What I want is to monitor the length of time a field spends on particular status. Specifically, I want to record the length of time that the record spends with a status value of 3. So if the record has its status changed to 3, the system 'starts the clock' and once the status changes away from 3, the system 'stops the clock'. This must also continue if the status subsequently returns to 3 at a later date (for the same record) and cumulatively produce the total amount of time that the record spent on status 3.
Practical example
March 19th: Record is set to status 3 (for the first time) March 21st: Record is set to status 1 March 25th: Record is set to status 3 (again) March 27th: Record is set to status 2
In this scenario, I want visibility that the record has spent four days on status 3 altogether. I don't need exact times (nearest day will do). Ideally the system will only count working days (although this is not a must-have).
Hello All... I'm very new to Access.. so please forgive my ignorance..
Here is the scenario..
I have a table with two fields named "item" & "description" that contains 10 records total.
I have another table with 100 records with the fields "invoice #","item", "price paid","date paid","time paid". The item fields are linked between the two, and the 100 records contain different invoices for these ten items.
I want to pull the price paid off of the latest invoice, based on the time and date... What is the easiest way to do this?
I have a table of SOPs/WIs. Each, with time, gets a new version - this I keep in the child table.
tblVersions ------------ VersionID (PK) SOPID(FK) Version (integer) IssueDate (date)
I want to make a list of the currently valid versions, i.e. for each SOPID pick the VersionID with the latest date.
One can do many things with subqueries and Max - functions, but after some experimentation I have stumbled upon this:
Code: SELECT Last(tblTest.VersionID) AS LastOfVersionID FROM tblTest WHERE (((tblTest.IssueDate)<Date()-10)) GROUP BY tblTest.SOPID;
The function Last has a bit tricky reputation and description on the web. It does yields the right result in my testcase though , see the attached db - run query3.
Query3
Code: LastOfVersionID 100 90 20 40 666 888 55 8
Update: Well, it isn't. Just changing the VersionID numbers to something other than an ascending sequence renders an incorrect result with the above query. So what is the best way to get the desired result? (Access 2007)
I'm having trouble with a simple query. They have an access database with a table like this (simplified for this example):
-------------------------------- Name Result Date -------------------------------- Bob 5 1/1/2014 Bob 6 2/2/2014* Bob 7 3/3/2015 Bob 8 5/4/2015* Len 5 1/1/2014 Len 6 2/2/2014* Len 7 3/3/2015 Len 5 7/4/2015* ---------------------------------
how I would write a query that gives me the latest result that each person earned in each year (I put a * symbol against the rows above that I am talking about)?
Bob 6 2/2/2014 Bob 8 5/4/2015 Len 6 2/2/2014 Len 5 7/4/2015
(The database is normalised and this table has an ID field).
I have a list of project, each of which have dates which work were carried out on them. Each project can have more than one date. I want to be able to find the last date that any work was carried out, and then calculate how many days have passed since that happened.
I have a form that contains a toggle button. When a record is complete and considered closed I click the toggle button. I want to make the form background turn red if I enter into a record that has been closed. :confused:
If this is not possible, is there something similiar that would stand out:rolleyes:
I have two tables. The first is called Drawing Register and contains the fields Drawing No (primary field) and Drawing Title.The second table is the Drawing Register Details table which contains the fields Drawing No (joined field - Drawing Register table), Revision, Revision Notes, Date Issued.
I have a query and report which will list all the revisions for each drawing. This is very important and useful. However I want a summary report which will only show the last revision for each drawing.
I copied the original query, turned on the Totals option and under the Date Issued field changed Group by to Max. However it is still returning all results for each drawing instead of only the last issue date for each drawing.
but the tricky part is the number could be suffixed with a revision. It is the latest revision I would like to find. For example, If I have a number followed by 3 revisions I would have:
I have 3 different tables in a DB that I need to combine to get information on for 1 report.
table 1- Has the main info, (CR#) doc number, when issued, due date, etc... table 2 - Is a Status table which in form view will show date and time of the status of a document and who has it. table 3 - have what type of document it is and how many submitted.
The reports needed are: open status (what is the status of that doc. who has it and only need the last status) and the report needs to have on it: the cr #, what type of doc.
I have done a query combining the 3 tables and it is not showing correctly here? I just need the last date entered into status.
SELECT Max(tblsignatures.date) AS MaxOfdate, (([ReportDate]-[DateIssued]))-((DateDiff("ww",[DateIssued],[ReportDate]))) AS [Total Days], tblsignatures.status, tblitem.ReportDate, tblcr.CR, tblcr.DateIssued, tblcr.DueDate, tblcr.ClosedDate, tblitem.item, [DueDate]-Date() AS DueDates FROM (tblsignatures INNER JOIN tblcr ON tblsignatures.cr = tblcr.CR) INNER JOIN tblitem ON tblcr.CR = tblitem.cr GROUP BY tblsignatures.status, tblitem.ReportDate, tblcr.CR, tblcr.DateIssued, tblcr.DueDate, tblcr.ClosedDate, tblitem.item, [DueDate]-Date() HAVING (((tblcr.ClosedDate) Is Null)
Giving up after a zillion tries. I have a table (tblLOADS) containing: BROKER, PUDATE, MATERIAL & DRIVER. I am able to create this query:
SELECT tblLOADS.L_ID, tblLOADS.BROKER, Max(tblLOADS.Pudate) AS MaxOfPudate, tblLOADS.Material, tblLOADS.Driver FROM tblLOADS GROUP BY tblLOADS.L_ID, tblLOADS.BROKER, tblLOADS.Material, tblLOADS.Driver HAVING (((Max(tblLOADS.Pudate))>0));
Problem: It's datasheet view displays all of the records for BROKERS, PUDATE, MATERIAL & DRIVER, instead of ONLY the records for the last PUDATE of each of the BROKERS, with their corresponding MATERIAL & DRIVER fields.