Ich bin in einer Situation, in der ich die Zeilen von zwei Spalten aktualisieren muss und ich bin nicht in der Lage, die richtige Lösung zu finden.Warum Zeile falsch in DB aktualisiert?
Ich habe Tabelle wie folgt aus:
table1 :
nid listName ltitle
1 lsn1 lst1
2 lsn2 lst2
und jetzt das nid ist Fremdschlüssel (listid) für table2
table2
nid listid listcol1 listcol2
1 1 "lstxt1" "lscol1" //belongs to lsn1
2 1 "lstxt2" "lscol2" //belongs to lsn1
3 1 "lstxt3" "lscol3" //belongs to lsn1
3 2 "lstxt4" "lscol4" //belongs to lsn2
Zum besseren Verständnis gibt es zwei Liste namens LSN1 und LSN2 und erste hat 2 Spalten listcol1 und listcol2 und listcol1 enthält die Daten die kommen durch eine Zeichenfolge, die ich durch "###" als Trennzeichen so etwas wie "lstxt1###lstxt2###lstxt3###"
ähnlich für listcol2
Mein versuchen, beide Tabelle in gespeichert prcodure auf Daten, die durch Benutzer geändert zu aktualisieren:
update table1 set [email protected] ,[email protected] //table 1 update and it works well
where [email protected]
update table2 set [email protected], listcol1=a.part,listcol2= b.part from //table2 update , problem is here
dbo.splitstring(@listcol1,'###') a inner join
dbo.splitstring(@listcol2,'###') b on a.id=b.id where [email protected]
Problem hier ist: (1) tabelle1 aktualisiert richtig, aber table2 aktualisierte Ausgang ist falsch (können sagen, dass ich zu aktualisieren versucht, für nid = 1 in table1):
listcol1 listcol2
"lstxt5" "lscol5" //belongs to lsn1
"lstxt5" "lscol5" //belongs to lsn1
"lstxt5" "lscol5"
Ich meine, es aktualisiert die erste Zeile in allen Zeilen. Wo, wie erwartete Ausgabe war:
listcol1 listcol2
"lstxt5" "lscol5" //belongs to lsn1
"lstxt6" "lscol6" //belongs to lsn1
"lstxt7" "lscol7"
(2), wenn der Benutzer hinzufügen, neue Zeile es nicht zeigen, das Update in dieser Reihe. Das muss es auch zeigen.