UPDATE records with already data exists

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

UPDATE records with already data exists

Post by sal21 »

have table1,
F1 F2 F3
1A 2 3
1A
1A

1A is a indexed filed

now possible to update the F2 and F3, based F1=1A and F2 and F3 is just filled, and F2 is null?

i need:
F1 F2 F3
1A 2 3
1A 2 3
1A 2 3


peraphs i just post and remember only to macke a new virtula table1_1 and join the F1 fields.... :sad: :scratch:

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: UPDATE records with already data exists

Post by HansV »

What if there are records like this?
S1824.png
Or is that impossible?
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

Re: UPDATE records with already data exists

Post by sal21 »

HansV wrote:What if there are records like this?
S1824.png
Or is that impossible?
no possible, the combination is always:

1A 2 3

in effect 1A is a silmilar ZIP code, 2 the way, 3 the city name

not possible to have zip code with different indication.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: UPDATE records with already data exists

Post by HansV »

You can use the following SQL:

UPDATE Table1 AS A INNER JOIN Table1 AS B ON A.F1 = B.F1 SET A.F2 = B.F2, A.F3 = B.F3 WHERE A.F2 Is Null AND B.F2 Is Not Null
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4370
Joined: 26 Apr 2010, 17:36

Re: UPDATE records with already data exists

Post by sal21 »

HansV wrote:You can use the following SQL:

UPDATE Table1 AS A INNER JOIN Table1 AS B ON A.F1 = B.F1 SET A.F2 = B.F2, A.F3 = B.F3 WHERE A.F2 Is Null AND B.F2 Is Not Null
tested and WORK!
TKS.