473,770 Members | 6,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1519
"Matthew Kramer" <mk********@hot mail.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("YearFl d","Table2","Ye arFld < " & [Table3].[YearFld],0)

GreaterMin : NZ(DMin("YearFl d","Table2","Ye arFld > " &
[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(DateF ld - LessMax < DateFld - GreaterMin,Less Max,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
2490
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 only way to find out the current state of a particular combination of attributes is to "select distinct on (id, ...) ... order by date desc". In the examples below, I've taken real output from psql and done a global search/replace on various...
10
15381
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 identical field names. The queries select a subset of the fields, so "Select *" is not really an option. Is there an easy way to change the source of a query, either in the design grid or SQL display? I suppose I could copy the SQL into WordPad...
2
3842
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 with 512Mb of ram and swap. This was just upgraded from 7.4 (just to make sure I'm current). Some of my settings in postgresql are giving fatal errors but I don't think my issue is related to my query problems. I also have a laptop running with...
6
4849
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 SalesManName AT Alan Time
7
3537
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 performs MySQL queries to a database. These queries are performed at regular intervals. Basically it is looking for fields that match certain criterias. Such fields are not present at all time. When the program finds such field, it then takes
27
18403
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 crosstab query itself - only use information FROM it to update a perfectly updatable table! Why the ---- would I get this error, when there are clearly NO permission issues, or issues in updating the table I'm trying to
5
3532
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 to 1800 stores of a national home improvement chain store. Every week I electronicaly receive an excel spreadsheet "inventory report" with 19,800 rows or records, which I import into my tblSalesData table. The table now has 10 weeks of data or...
5
1943
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 following code to define a query. I run the query and then get a record deleted errors (3167) when I go to export to a spreadsheet. It works if I put in a delay between the query and the
1
2765
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 have a table containing records for each job done, the records contain date, employee name, job done (a code representing the type of job), cost code (another code), regular hours, and overtime hours. The tricky part is that more than one job can...
2
1749
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 of patients seen and whether the test was done or not. So in my query I'm grouping by PatientID and PatientName, for my criteria I have a couple of where statements for LocationID and Date. To show if the test was done I have a field Max(.) AS...
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.