473,383 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to get next row value in query rows (Access 2002)

I have the following table in Access 2002:
Empl | Date | Location
0001 | 12/1/1990 | POA
0001 | 3/1/1992 | SYL
0001 | 6/1/2000 | VNY
0002 | 4/3/2002 | TOA
0002 | 8/15/2006 | PAA

I need to create another column named EndDate that will pick up the next row value like this:
Empl | Date | Location | End Date
0001 | 12/1/1990 | POA | 3/1/1992
0001 | 3/1/1992 | SYL | 6/1/2000
0001 | 6/1/2000 | VNY | null
0002 | 4/3/2002 | TOA | 8/15/2006
0002 | 8/15/2006 | PAA | null

Could someone help please?
Jul 11 '08 #1
6 9773
nico5038
3,080 Expert 2GB
In general I use an autonumber to get access to a previous row.
When you add an autonumber field to the table you can create a query with:
select autonumfield - 1 as OldKey, ...

Joining the original table with the query by the autonum field will give the possibility to show two rows at the same time. Now an IIF statement can create the Enddate like:
EndDate:IIF(Key = OldKey,[Date],Null)

Best to rename the Date field to e.g. StartDate, as Date is also a function and thus a reserved word and can cause trouble!

Nic;o)
Jul 12 '08 #2
ADezii
8,834 Expert 8TB
You cab do it in code by created Nested Loops both pointing to the same Recordset, but with only the inner loop updating.
Jul 12 '08 #3
Thanks for all the suggestions.
Jul 14 '08 #4
nico5038
3,080 Expert 2GB
Keep us posted :-)

Nic;o)
Jul 14 '08 #5
Thank you sooooooooo much nico5038 . I GOT it. I did what you suggested. You're super. Thanks again.
Jul 14 '08 #6
nico5038
3,080 Expert 2GB
Glad I could help.

Be sure to have no gaps in the autonumber sequence, else the trick won't work.

Nic;o)
Jul 15 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael Hill | last post by:
I have some query like: select my_field from my_table and there are 500000 rows in the table, how do I tell Oracle to display the next 33? i tried select my_field from my_table next 33 and...
7
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time =...
8
by: Adam Nemitoff | last post by:
Is is possible to construct a SELECT statement that contains a WHERE clause that uses the value from a column in the "next" row? ie. given a table with a single field named "myField" with the...
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
2
by: Andrew Stanton | last post by:
Hi, I have a query that returns a sum for all values found that match the criteria. I am wanting to place this value in a textbox on its own so I can refer to it elsewhere. I have used the...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
7
by: FinanceGuy2 | last post by:
I’m trying to implement the recommended solution regarding “How to get next row…” that was posted July 12, 2008, but am having trouble with the “Autonum” part using Access 2003. In this case I am...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.