473,406 Members | 2,451 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,406 software developers and data experts.

Query help needed

I am trying to do something with an Access SQL query that I have never
done. I can see how it SHOULD work in my head, but can't seem to make
it work in reality. I think I have it close, but my SQL syntax must be
off.

What I WANT to do:
I have two tables. One (tbl_hours_new) is an SQL linked table through
ODBC, which reads just like any other table in Access. The second
(tbl_hours_Palm1) is just a regular table. I want to be able to run a
single query that will read the data in the first table and update (or
replace) the information is the second table based on the id number
(which will be identical).

Here is my current SQL statement:
UPDATE tbl_hours_new SET
`Date` = (Select `Date` from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id),
Employee = (Select `Employee` from tbl_hours_new where
tbl_hours_new.id = tbl_hours_Palm1.id),
Job = (Select `Job` from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id),
Hours = (Select `Hours` from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id),
PalmID = (Select `PalmID` from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id)

WHERE exists (Select id from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id);
Can anyone tell me where I have gone wrong?

Andrew

Nov 13 '05 #1
1 1118
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You're updating the table tbl_hours_new w/ it's own data. You say you
want to update/replace data in the "second table." From the context of
that paragraph I'm assuming that you want to update tbl_hours_Palm1 (the
second table you mentioned) w/ data from tbl_hours_new (the first table
you mentioned). If so then try this (these queries will only update
current data. It will not add new data):

UPDATE tbl_hours_Palm1
SET [Date] = (Select [Date] from tbl_hours_new
where tbl_hours_new.id = tbl_hours_Palm1.id),
Employee = (Select Employee from tbl_hours_new
where tbl_hours_new.id = tbl_hours_Palm1.id),
Job = (Select Job from tbl_hours_new
where tbl_hours_new.id = tbl_hours_Palm1.id),
Hours = (Select Hours from tbl_hours_new
where tbl_hours_new.id = tbl_hours_Palm1.id),
PalmID = (Select PalmID from tbl_hours_new
where tbl_hours_new.id = tbl_hours_Palm1.id)

WHERE exists (Select * from tbl_hours_new
where tbl_hours_new.id = tbl_hours_Palm1.id);

If you want to update tbl_hours_new w/ data from tbl_hours_Palm1:

UPDATE tbl_hours_new
SET [Date] = (Select [Date] from tbl_hours_Palm1
where tbl_hours_new.id = tbl_hours_Palm1.id),
Employee = (Select Employee from tbl_hours_Palm1
where tbl_hours_new.id = tbl_hours_Palm1.id),
Job = (Select Job from tbl_hours_Palm1
where tbl_hours_new.id = tbl_hours_Palm1.id),
Hours = (Select Hours from tbl_hours_Palm1
where tbl_hours_new.id = tbl_hours_Palm1.id),
PalmID = (Select PalmID from tbl_hours_Palm1
where tbl_hours_new.id = tbl_hours_Palm1.id)

WHERE exists (Select * from tbl_hours_Palm1
where tbl_hours_new.id = tbl_hours_Palm1.id);

Note: In JET SQL the column name delimiter is a square bracket and not
a single quote. In standard SQL the column name delimiter is a double
quote.

If you want to add new data try this:

INSERT INTO <target table> ([Date], Employee, Job, Hours, PalmID)
SELECT [Date], Employee, Job, Hours, PalmID
FROM <source table> As S LEFT JOIN <target table> As T
ON S.id = T.id
WHERE T.id IS NULL

Replace <target table> w/ the name of the table you want to insert data
into, and replace <source table> w/ the name of the table you want to
get the data from.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQnZ9noechKqOuFEgEQKfbACgyldj6aaFWhFJOA8ueCBmnm qQmp8AoPYU
dwE+V6RVxdRe2uUjBKWz5xD0
=lZm4
-----END PGP SIGNATURE-----
JellyMan wrote:
I am trying to do something with an Access SQL query that I have never
done. I can see how it SHOULD work in my head, but can't seem to make
it work in reality. I think I have it close, but my SQL syntax must be
off.

What I WANT to do:
I have two tables. One (tbl_hours_new) is an SQL linked table through
ODBC, which reads just like any other table in Access. The second
(tbl_hours_Palm1) is just a regular table. I want to be able to run a
single query that will read the data in the first table and update (or
replace) the information is the second table based on the id number
(which will be identical).

Here is my current SQL statement:
UPDATE tbl_hours_new SET
`Date` = (Select `Date` from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id),
Employee = (Select `Employee` from tbl_hours_new where
tbl_hours_new.id = tbl_hours_Palm1.id),
Job = (Select `Job` from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id),
Hours = (Select `Hours` from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id),
PalmID = (Select `PalmID` from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id)

WHERE exists (Select id from tbl_hours_new where tbl_hours_new.id =
tbl_hours_Palm1.id);

Can anyone tell me where I have gone wrong?

Nov 13 '05 #2

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

Similar topics

10
by: Irlan agous | last post by:
$query = "update reactie,form set 'reactie.persemail' = 'form.email' where 'reactie.persid' = 'form.id' AND reactie.persemail='' "; How can i get this query to work? Irlan
20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
3
by: Eagle | last post by:
Hi all, This one's drivin' me nuts. Any help would be appreciated. (Access 2000). I have 3 tables: tblTools: having the basic data of a tool and a field (txt) showing yes or no with regard to...
3
by: cover | last post by:
I have a table with 50 fields that receive input depending on whether that input came in from a 'shaker' form or a 'conveyor' form. Input from the 'conveyor' form might populate 25 fields while...
3
by: faceman28208 | last post by:
Over the past few years I have consulted on six large projects that all independently arrived at the same moronic design desision: The use of SQL query classes. No, I don't mean a class...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
8
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all that I have read show dynamic SQL passed to Access: ...
2
by: sara | last post by:
I am helping a non-profit track their elder clients and care given to the clients. The organization would like a report that shows various info on ALL clients, such as: # in each town, # and...
20
by: exipnakias | last post by:
Hello Guys. In a form I created a listbox which looks up the values of a table. I want: 1) ..to create a query where a parameter will be needed in order to be loaded. But I do not want to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
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...
0
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,...
0
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...

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.