473,976 Members | 10,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Palm 1) 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.i d =
tbl_hours_Palm1 .id),
Employee = (Select `Employee` from tbl_hours_new where
tbl_hours_new.i d = tbl_hours_Palm1 .id),
Job = (Select `Job` from tbl_hours_new where tbl_hours_new.i d =
tbl_hours_Palm1 .id),
Hours = (Select `Hours` from tbl_hours_new where tbl_hours_new.i d =
tbl_hours_Palm1 .id),
PalmID = (Select `PalmID` from tbl_hours_new where tbl_hours_new.i d =
tbl_hours_Palm1 .id)

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

Andrew

Nov 13 '05 #1
1 1140
-----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.i d = tbl_hours_Palm1 .id),
Employee = (Select Employee from tbl_hours_new
where tbl_hours_new.i d = tbl_hours_Palm1 .id),
Job = (Select Job from tbl_hours_new
where tbl_hours_new.i d = tbl_hours_Palm1 .id),
Hours = (Select Hours from tbl_hours_new
where tbl_hours_new.i d = tbl_hours_Palm1 .id),
PalmID = (Select PalmID from tbl_hours_new
where tbl_hours_new.i d = tbl_hours_Palm1 .id)

WHERE exists (Select * from tbl_hours_new
where tbl_hours_new.i d = 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.i d = tbl_hours_Palm1 .id),
Employee = (Select Employee from tbl_hours_Palm1
where tbl_hours_new.i d = tbl_hours_Palm1 .id),
Job = (Select Job from tbl_hours_Palm1
where tbl_hours_new.i d = tbl_hours_Palm1 .id),
Hours = (Select Hours from tbl_hours_Palm1
where tbl_hours_new.i d = tbl_hours_Palm1 .id),
PalmID = (Select PalmID from tbl_hours_Palm1
where tbl_hours_new.i d = tbl_hours_Palm1 .id)

WHERE exists (Select * from tbl_hours_Palm1
where tbl_hours_new.i d = 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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQnZ9noechKq OuFEgEQKfbACgyl dj6aaFWhFJOA8ue CBmnmqQmp8AoPYU
dwE+V6RVxdRe2uU jBKWz5xD0
=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_Palm 1) 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.i d =
tbl_hours_Palm1 .id),
Employee = (Select `Employee` from tbl_hours_new where
tbl_hours_new.i d = tbl_hours_Palm1 .id),
Job = (Select `Job` from tbl_hours_new where tbl_hours_new.i d =
tbl_hours_Palm1 .id),
Hours = (Select `Hours` from tbl_hours_new where tbl_hours_new.i d =
tbl_hours_Palm1 .id),
PalmID = (Select `PalmID` from tbl_hours_new where tbl_hours_new.i d =
tbl_hours_Palm1 .id)

WHERE exists (Select id from tbl_hours_new where tbl_hours_new.i d =
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
1915
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
10202
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
2437
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. I need a query that will return the c date for TypeID 18 if it exist else the date for TypeID 1, for all jobs. the table structure is the following Job TypeID
3
1460
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 being in-stock. Unique toolNr is the primary key. tblOut: stores info on emloyee_ID and date of any occasion that the tool is being handed over to someone. (tblTools stock will be set to No). Primary
3
1975
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 input from the 'shaker' form will populate another 20-25 fields but not the same fields (however there are about 10 common fields to both). I'd thought about using two tables (one for 'conveyor' and the other for 'shaker') but thought I'd try just...
3
1546
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 hierararchy like: SQL Query UpdateQuery SelectQuery Where you hide the details of the underlying database API. (Along the lines of what Rogue Wave does.)
0
2470
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 the whole. I really need MySQL wizz to give me a hand (and maybe refer me to books to get me to the wizz level myself). First off, english is a second language to me and sometimes my sentences might be a little awkward. Please forgive me. Mon...
8
8070
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: WHERE LIKE '" & ASPvar & "' % ORDER BY ... However, my call is similar to: conn.qMyLookup strVar, rs
2
1979
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 Percent Male, Female, Smoker, # in age range # that use wheelchair or walker.
20
5271
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 write the parameter, I want to select a row from the listbox and after clicking in a button, the query to automatically take the current value of listbox as the needed parameter and then to load the query. (The Inputbox for "Enter Parameter" will...
0
10355
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
11821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11408
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
11574
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
10084
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...
0
6416
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5155
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
2
4731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3761
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.