PDA

View Full Version : SQL UPDATE ?!



Jamikl
20-04-05, 10:33
Hallo, ich habe hier eine Anforderung die ich einfach nicht mit SQL gelöst bekomme

folgendes:

Tabelle1

FLD1 FLD2
A
A
A
B
B
B
B
C
C
C

Tabelle2

FLD1 | FLD2
A | 12345
B | 32145
C | 23456



Ich muss in die Tabelle 1 in das Feld FLD2 die Werte von Tabelle2 FLD2 eintragen wobei gilt FLD1 = FLD2 und FLD2 <> ' '


Bisher habe ich folgendes Statement:

Update tab1 set fld2 = (Select fld2 from tab2 where tab1.fld1 = tab2.fld1 and tab2.fld2 <> ' ')



Das will einfach nicht funktionieren.


schon mal Danke

Fuerchau
20-04-05, 10:53
Du musst den Update mit einer Where-Bedingung ergänzen, da der Subselect ja auch NULL-Werte liefern kann:

Update tab1 set fld2 = (Select fld2 from tab2 where tab1.fld1 = tab2.fld1 and tab2.fld2 <> ' ')
where fld1 in (Select fld1 from tab2 where tab1.fld1 = tab2.fld1 and tab2.fld2 <> ' ')