473,406 Members | 2,387 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.

Update Query - update fields from one table to another, possible primary key problem

1
Hi, this is my first ever post, so go easy on me...

I want to update some fields from table 'cases' to some fields in another table 'casesandcontrols'. For example I want to add the PSA data from the PSA field in the 'cases' table to the 1PSA field in the 'casesandcontrols' table, and the data must match up to the corresponding ID. I tried to use an update query to do this but it didn't like how the tables had a primary key, so I removed the primary key from the tables and now it inserts the PSA data into new records and not into the corresponding ID records... any suggestions? My SQL statement is below. Many thanks for your help. Kim

UPDATE [casesandcontrols] RIGHT JOIN [cases] ON ([casesandcontrols].[1PSA] = [cases].PSA) AND ([casesandcontrols].ID = [cases].ID) SET [casesandcontrols].[1PSA] = [cases].PSA
WHERE ((([casesandcontrols].[1PSA]) Is Null));
Jul 6 '07 #1
1 1753
kepston
97 Expert
Hi, this is my first ever post, so go easy on me...

I want to update some fields from table 'cases' to some fields in another table 'casesandcontrols'. For example I want to add the PSA data from the PSA field in the 'cases' table to the 1PSA field in the 'casesandcontrols' table, and the data must match up to the corresponding ID. I tried to use an update query to do this but it didn't like how the tables had a primary key, so I removed the primary key from the tables and now it inserts the PSA data into new records and not into the corresponding ID records... any suggestions? My SQL statement is below. Many thanks for your help. Kim

UPDATE [casesandcontrols] RIGHT JOIN [cases] ON ([casesandcontrols].[1PSA] = [cases].PSA) AND ([casesandcontrols].ID = [cases].ID) SET [casesandcontrols].[1PSA] = [cases].PSA
WHERE ((([casesandcontrols].[1PSA]) Is Null));
Your SQL is trying to JOIN two tables on a field (1PSA) that you are looking for Null in the WHERE clause.
What it is essentially saying is:
Expand|Select|Wrap|Line Numbers
  1. Where PSA equals 1PSA set 1PSA to be the same as PSA but only when 1PSA is empty
The following may be of more use
Expand|Select|Wrap|Line Numbers
  1. UPDATE [casesandcontrols] RIGHT JOIN [cases] ON ([casesandcontrols].ID = [cases].ID) SET [casesandcontrols].[1PSA] = [cases].PSA
  2. WHERE ((([casesandcontrols].[1PSA]) Is Null));
Jul 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: mo | last post by:
I need to bring the ssn's into UniqueSups (supervisors) from tblNonNormalized. My inherited DB is not normalized and I find it extremely irritating due to the workarounds needed. I created...
2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
2
by: Pete | last post by:
Before I get started with the question, does anyone have a (single) good book recommendation for database design? Not an Access-specific book, but something geared toward helping me figure out...
0
by: Jason | last post by:
I have a primary form which is used to enter/edit data in a table named Test_Results. On this primary form there is a subform which displays site addresses. This subform is linked to the primary...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
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 ...
3
by: OzNet | last post by:
I have inherited a database for placing job seekers into jobs. The original table has 3 fields which contain job preferences using codes which had to be looked up in a book. There are around 5000...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
11
by: stantron | last post by:
Setup: I only have one database with one table in it. The first page has a form that adds a record (w/ 6 fields in it) to the mySQL database's lone table via PHP. This works fine. I also have a PHP...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...
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...

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.