473,386 Members | 1,715 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,386 software developers and data experts.

query- how can this be done?

How would be the best way to do this in Access?

I have two tables. The first table has all the rows of data. The first
column of this table has a country name, the second has a year and the
third column is the data value.

The second table is just a list of standard years ie. 1980, 1985, 1990,
1995).

Is there a way to arrange a query so that all of the rows in table 1
which do not have a standard year (according to the list in table 2) in
the year column are noted and a new table (table 3) is created from
which does the following:

- for all rows in table 1 which do not have a standard year, the content
of year (in the year column) is changed to the standard year which is
closest. ie. if non-standard year is 1992, the standard year is 1990).
- a new column is added at the end with the field heading "notes". In
this column for the row, the original non-standard year ie. 1992 is put
as words "this data refers to 1992".

For example, if the tables are as follows then:

table 1:
country year value
austria 1992 11.5

table 2:
standardyears
1990
1995

table 3:
country year value notes
austria 1990 11.5 this data refers to 1992

Looking forward to your suggestions.

Matthew Kramer


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #1
3 1493
"Matthew Kramer" <mk********@hotmail.com> wrote in message
news:41**********************@news.newsgroups.ws.. .
How would be the best way to do this in Access?

I have two tables. The first table has all the rows of data. The first
column of this table has a country name, the second has a year and the
third column is the data value.

The second table is just a list of standard years ie. 1980, 1985, 1990,
1995).

Is there a way to arrange a query so that all of the rows in table 1
which do not have a standard year (according to the list in table 2) in
the year column are noted and a new table (table 3) is created from
which does the following:

- for all rows in table 1 which do not have a standard year, the content
of year (in the year column) is changed to the standard year which is
closest. ie. if non-standard year is 1992, the standard year is 1990).
- a new column is added at the end with the field heading "notes". In
this column for the row, the original non-standard year ie. 1992 is put
as words "this data refers to 1992".

For example, if the tables are as follows then:

table 1:
country year value
austria 1992 11.5

table 2:
standardyears
1990
1995

table 3:
country year value notes
austria 1990 11.5 this data refers to 1992

I've replaced you table names with ones that are more meaningful. This
should work ...

select c.country,
(
select top 1 y2.standardYear
from years as y2
order by abs(c.year-y2.standardYear)
), value, "this data refers to " & c.year as notes
into Matthew
from countries as c
left outer join years y on c.year = y.standardYear
where y.standardYear is null

Nov 13 '05 #2
Matthew Kramer wrote:
How would be the best way to do this in Access?

I have two tables. The first table has all the rows of data. The first
column of this table has a country name, the second has a year and the
third column is the data value.

The second table is just a list of standard years ie. 1980, 1985, 1990,
1995).

Is there a way to arrange a query so that all of the rows in table 1
which do not have a standard year (according to the list in table 2) in
the year column are noted and a new table (table 3) is created from
which does the following:
Yes. Create a query. Query/New/Design. Select Table1 and Table2.
Create a reference line/link by dragging YearFld To YearFld. Dbl-click
on the line and select All records in Table1 and All Records that match
in Table2 (may be option 2 or 3). Drag the asterisk (*) to the first
column in the directory. Drag the year from table 2 to the second
column. In the criteria, enter Is Null. Run it. If acceptable, select
Query from the designer menu and select MakeTable and save to Table3.
- for all rows in table 1 which do not have a standard year, the content
of year (in the year column) is changed to the standard year which is
closest. ie. if non-standard year is 1992, the standard year is 1990).
- a new column is added at the end with the field heading "notes". In
this column for the row, the original non-standard year ie. 1992 is put
as words "this data refers to 1992".
Open up the table3 and add a new field to hold the notes. If you are
going to merge the tables together, simply create the notes field before
you run any query.

Create an update query to store the new notes. Create a column like
NewNotes:"This data refers to " & Table3!YearFld
and run.

You will have to make multiple passes or queries.

Create a new query as above but select only Table3. In a column you
could enter.
LessMax : NZ(DMax("YearFld","Table2","YearFld < " & [Table3].[YearFld],0)

GreaterMin : NZ(DMin("YearFld","Table2","YearFld > " &
[Table3].[YearFld],0)

This will pull the closest less than/greater than years.

Now create another update query for Table3. Enter something like
Expr1:IIF(DateFld - LessMax < DateFld - GreaterMin,LessMax,GreaterMin)

and update this to DateFld.

This is a general outline. I am assuming you know how to create
maketable/update queries and can create an expression in a query.


For example, if the tables are as follows then:

table 1:
country year value
austria 1992 11.5

table 2:
standardyears
1990
1995

table 3:
country year value notes
austria 1990 11.5 this data refers to 1992

Looking forward to your suggestions.

Matthew Kramer


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 13 '05 #3
Many thanks for the suggestions. I will try them out.

Matthew

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the...
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
2
by: Keith C. Perry | last post by:
Ok, I've tried a number of things here and I know I'm missing something but at this point my head is spinning (i.e. lack of sleep, too much coffee, etc...) My environment is PG 7.4.3 on Linux...
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 ...
7
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that...
27
by: Bob | last post by:
running access 2k; mdb w/ linked tables to another mdb (front/back-end); trying to run a query that updates a table FROM information from a crosstab query. I AM NOTT trying to update the...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
5
by: darnnews | last post by:
Hi, I have been creating a database to keep track of press clippings, but I have hit a couple stumbling blocks. Any help is much appreciate. 1) Seeing if my query is done I have the...
1
by: Rob Woodworth | last post by:
Hi, I'm having serious problems getting my report to work. I need to generate a timesheet report which will contain info for one employee between certain dates (one week's worth of dates). I...
2
by: dez5000 | last post by:
I have a query that is pulling a list of patients seen within a certain time frame at certain locations and it also shows whether they had a certain test done. I want to report by location the list...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.