View Full Version : Add data from previous record if blank


mbc321
08-08-2009, 01:29 PM
I have a table with "Date" and "Rate" fields. Not every record contains a value in the "Rate" field. is there a query that would insert the value from previous record in case the "Rate" field is null?
The sample table looks like this:

Date;Rate
20070101;100
20070102;
20070103;
20070104;200
20070105;205
20070106;206
20070107;
20070108;195

The result schould look like this:

Date;Rate
20070101;100
20070102;100
20070103;100
20070104;200
20070105;205
20070106;206
20070107;206
20070108;195

pls i need used Query
Thank you

jjturner
08-08-2009, 01:57 PM
Hello and Welcome!

Your data looks like it may be coming from a Pivot Table in Excel, or something along those lines. So my first suggestion would be to see if you can find the source detail data where your current data format is generated from, then use that instead (which is presumably already in the format you're trying to get it back to).

In lieu of that, you would essentially need to use correlated Subqueries to update your values in the [Rate] field.

And lastly, you should change the name of your date field from [Date] to something else. "Date" is a reserved word in Access, which basically means when you use that word, you're telling Access to perform a function. So by naming your field [Date] you're setting yourself up for confusion and unexpected database behavior.

HTH,
John