Autor Beitrag
Flash106
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Mi 09.03.05 13:47 
Hallo,

wie kann ich Daten aus einer Tablle in einer andere kopieren? Die feldnamen in beiden TBs sind identisch. In der ersten Tabelle (quelle) sind ca 40 felder in der Zieltabelle viel mehr...es sollen die daten aus tabelle 1 in die entsprechenden felder aus Tabelle 2 eingetragen werden. wie realisiere ich das?!
hab hier mal was aber das klappt nicht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
...
     SQLQuery1.Close;
     SQLQuery1.SQL.Clear;
     SQLQuery1.Sql.Add('SELECT * FROM tbInteressent WHERE vID = ' + vDatensatzID);
     SQLQuery1.Open;
...
    for i := 1 to Datenmodul.SQLQuery1.Fields.Count - 1 do
    begin
      vFeldName := Datenmodul.SQLQuery1.Fields[i].FieldName;
      vFeldinhalt := Datenmodul.SQLQuery1.FieldByName(vFeldName).AsString;
      Datenmodul.mySQLQuery('UPDATE tbTeilnehmer SET ' +vFeldName+ ' = ' + QuotedStr(vFeldinhalt) + ' WHERE vPersNr = ' + edNeuePersNr.Text); <-- hier tritt der fehler auf "Listenindex überschreitet das maximun 2" ??
    end;
  end;


danke schonmal... bitte um eine lösung :)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 09.03.05 13:57 
Nächstesmal aber schreiben, was da nicht klappt.
Hast diesen Thread schon gesehen?
Die suche mit "Datensatz kopieren" zeigt den nämlich auch an. :wink:
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Do 17.03.05 13:18 
Hallo,

ich habe es jetzt nach dem prinzip versucht:

ausblenden Quelltext
1:
2:
3:
4:
insert into Zieltabelle
       select * from Quellentabelle
       where Bedingung1 = Bedingung1
         and Bedingung2 = Bedingung2


da die tabellen aber nicht identisch sind klappt das nicht so recht :( ... die ziel tabelle umfasst sehr viel mehr felder... und nun??

der Fehler lautet:

ausblenden Quelltext
1:
INSERT-Fehler: Spaltenname oder Anzahl der übergebenen Werte entspricht nicht der Tabellendefinition.					


was muss ich genau hinschreiben damit ich die daten kopieren kann??
Danke schonmal!!!

Bianca
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 17.03.05 13:58 
www.w3schools.com/sql/sql_insert.asp
Der link beschreibt doch ganz gut, wie es funktioniert.
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Do 17.03.05 14:00 
ja aber die daten sollen ja nicht in VALUES stehen sondern aus einer anderen Tabelle kommen... ppuuhh... ist anstrengend :( .. klappt halt nicht... :(
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Do 17.03.05 14:01 
Gibt es auch die möglichkeit mit UPDATE daten aus einer in die andere tabelle zu kopieren?? Also nicht mit insert into blabla.. sondern update in verbindung mit select from usw... ??
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 17.03.05 14:12 
ausblenden Quelltext
1:
2:
INSERT INTO Tabelle1 (Spalte,...)
    SELECT Spalte,.... from Tabelle2