Autor Beitrag
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 03.10.04 11:50 
hi,

wie kann ich den inhalt einer tabelle in eine andere kopieren, ohne mir die finger wund zu tippen (mit SQL)?

bsp:
die 2 tabellen sind exakt gleich (also die Felder) nur ihr Inhal tist natürlich anders.
wie kann ich jetzt aus tabelle 1 zeilen auswählen und sie komplett an tabelle 2 anhängen
ohne bei INSERT bei VALUES alle Felder angeben zu müssen.

Tabelle 1
ausblenden Quelltext
1:
2:
3:
Name | Alter
Al   | 22
Jo   | 33

Tabelle 2
ausblenden Quelltext
1:
2:
3:
Name | Alter
Micha| 34
Klaus| 67


jetzt möchte ich alle zeilen aus tabelle 2 in tabelle 1 einfügen deren name Klaus ist, dachte da an sowas wie:
ausblenden Quelltext
1:
2:
3:
INSERT INTO Tabelle1
VALUES SELECT * FROM Tabelle2
WHERE Name = 'Klaus'

funktioniert aber ja nicht

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: So 03.10.04 17:08 
Theoretisch sieht das gut aus. Habe leider gerade keine DB zum Test zur Verfügung. Eventuell musst du das Select in Klammern setzen.
Was fürn Fehler bekommst du denn?
GSE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 03.10.04 20:12 
Zitat:
Was fürn Fehler bekommst du denn?
Zitat:
Invalid use of keyword.
token: SELECT
Line Number: 2
EDBEngineError


mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: So 03.10.04 20:53 
Zuerst frage ich dich was für eine Datenbank du benutzt. Kann sein, daß ich es überlesen habe, aber ich sehe es nicht. Was Oracle angeht, so ist da kein Fehler drinn. Ich würde zwar empfehlen WHERE UPPER(Name) = UPPER('Klaus') und dann das ganze noch mit Semikolon ";" abzuschließen, aber sonst kein Fehler.

Allerdings sehe ich schon an der Fehlermeldung, daß es kein Oracle ist. Und deshalb stellt sich mir die Frage ob deine Datenbank überhaupt aus Unterabfragen füllen kann? Welche Datenbank benutzt du?

_________________
Gruß
Martin
GSE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: So 03.10.04 21:50 
ok, hab ich ich vergessen zu sagen, sry.
leider muss ich es mit 'ner Paradox machen (vorgabe), also scheint sie es nicht zu unterstützen, geht das trotzdem noch irgendiwe anders?

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: So 03.10.04 22:30 
Wenn es Oracle wäre, dann mit PL/SQL und Cursors.

Ich kenne keine Möglichkeit wie man eine eine Tabellenstruktur an ein Rekord übegeben kann. Wenn es keine gibt, dann wirst du einzelene Variablen definieren müssen und dann mit einer For Schleife. Aber ich kenn mich kaum mit Paradox aus. Vielleicht kennt einer eine bessere Methode.

_________________
Gruß
Martin
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 04.10.04 07:16 
Stichwort: TBatchMove.
Ich glaube, damit sollte es funktionieren.
Über eine Schleife wird das vermutlich grottenlangsam. Ich habe mir mal eine kleine Prozedur dafür geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
// Kleine Hilfsprozedur:
Function DBEmpty(q : TQuery) : Boolean;
begin
  Result := not q.Active;
  if not Result then begin
    Result := q.eof and q.bof;
  end;
end;

// Eigentliche Prozedur
procedure TdtmMain.KopiereAktuellenDatensatzMitAppend(qQuelle, qZiel : TQuery; Speichern : Boolean);
var
  cnt : Integer;
  arr : array of variant;
begin
  if qQuelle.Active and (not DBEmpty(qQuelle)) then begin // Startbedingung erfüllt?
    SetLength(arr, qQuelle.FieldCount); // Länge für dynamisches Array setzen
    for cnt := 0 to qQuelle.FieldCount - 1 do begin // Array mit Daten aus Quelle füllen
      arr[cnt] := qQuelle.Fields[cnt].AsVariant;
    end;
    qZiel.Append; // Neuer DS im Ziel
    for cnt := 0 to qZiel.FieldCount - 1 do begin // Array in DS schreiben
      qZiel.Fields[cnt].AsVariant := arr[cnt];
    end;
    if Speichern then begin // DS gleich speichern?
      qZiel.Post;
    end;
  end;
end;

Viel Spaß
GSE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mo 04.10.04 15:21 
thx, :D

hab's noch'n bisschen angepasst (da bei querys append net funzt)
jetzt geht er alle gefundenen DSs durch
wens interessiert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
// Datensätze einer Query an eine datenbank anhängen
procedure CopyDB(qQuelle: TQuery; qZiel: TTable; Speichern: Boolean);
var
 cnt, curDS: Integer;
 arr: array of array of variant;
begin
 if qQuelle.Active and (not DBEmpty(qQuelle)) then begin // Startbedingung erfüllt?
  SetLength(arr, qQuelle.RecordCount, qQuelle.FieldCount); // Länge für dynamisches Array setzen

  for curDS := 0 to qQuelle.RecordCount - 1 do begin

   for cnt := 0 to qQuelle.FieldCount - 1 do begin // Array mit Daten aus Quelle füllen
    arr[curDS, cnt] := qQuelle.Fields[cnt].AsVariant;
   end;
   qZiel.Append; // Neuer DS im Ziel
   for cnt := 0 to qZiel.FieldCount - 1 do begin // Array in DS schreiben
    qZiel.Fields[cnt].AsVariant := arr[curDS, cnt];
   end;

   qQuelle.Next;

  end;

  if Speichern then begin // DS gleich speichern?
   qZiel.Post;
  end;
 end;
end;


nochmal danke

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 04.10.04 15:30 
Dass das Append bei TQuery nicht immer funktioniert ist schon klar. Für meine Routine war die Aufgabenstellung nur eine andere. Da ist es eigentlich klar, dass die Query dazu in der Lage ist. Aber trotzdem werde ich da noch eine Prüfung oder ein Try...Except einbauen.
Ansonsten: Gern geschehen.
kachel81
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63



BeitragVerfasst: Di 05.10.04 09:15 
Im Interbase wäre es

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
insert into tablename
  (
  Field1,
  Field2,
  ...
  )
  select
    Field1,
    Field2,
    ...
  from
    tablename
  where
    ...