Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi Eine von einer Prozedur stammende datenmenge ändern (https://www.delphipraxis.net/19571-eine-von-einer-prozedur-stammende-datenmenge-aendern.html)

Nightfly 5. Apr 2004 15:54


Eine von einer Prozedur stammende datenmenge ändern
 
Es geht um folgende Prozedur:
SQL-Code:
CREATE PROCEDURE PLANSUMMIEREN (
    STELLE CHAR(9),
    JAHR INTEGER)
RETURNS (
    BEREICH INTEGER,
    BEZ CHAR(32),
    ALLES NUMERIC(9,2),
    JAN NUMERIC(9,2),
    FEB NUMERIC(9,2),
    MAR NUMERIC(9,2),
    APR NUMERIC(9,2),
    MAI NUMERIC(9,2),
    JUN NUMERIC(9,2),
    JUL NUMERIC(9,2),
    AUG NUMERIC(9,2),
    SEP NUMERIC(9,2),
    OKT NUMERIC(9,2),
    NOV NUMERIC(9,2),
    DEZ NUMERIC(9,2))
AS
begin
  for select ID,BEZ from MAIN B where B.STELLE = :stelle
  into :BEREICH, :BEZ do
  begin
    if (exists (select * from vorgabe where (ID = :bereich) and (del = 0))) then
    begin /* die direkten parents berechnen */
    if (not exists (select id from hauptkeys where id = :bereich)) then
      begin
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr
      into :ALLES;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 1
      into :JAN;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 2
      into :FEB;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 3
      into :MAR;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 4
      into :APR;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 5
      into :MAI;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 6
      into :JUN;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 7
      into :JUL;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 8
      into :AUG;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 9
      into :SEP;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 10
      into :OKT;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 11
      into :NOV;
      select sum(WERT) from PLANUNG P, MAIN M
      where (P.stelle = :stelle) and (M.stelle = P.Stelle) and (P.bereich = M.ID) and (M.parent = :BEREICH) and P.Jahr = :jahr and P.monat = 12
      into :DEZ;
      suspend;
      end
     end
end
Mittels eines DataSet wird diese über eine DataSource in einem DBGrid angezeigt. Im SelectSQL des Dataset steht also select * from plansummieren.

So, jetzt wirds haarig.

Ich würde gern im grid einfach drin rum schreiben können. Das jahr steht in einer variablen in meinem Programm. Den monat kann ich ja aus der spalte ermitteln. der wert für stelle steht ebenfalls in einer variablen meines programms, und der wert bereich lässt sich aus der zeile, in der die eingabe erfolgt,ermitteln
Also habe ich einen kompletten datensatz für die Tabelle Planung zusammen. Bloß wie bekomm ich die daten jetzt da rein?

In meinem Leichtsinn hab ich als InsertSQL in das Data set,welches oben beschriebenes select statement enthält,folgendes reingeschrieben:

INSERT INTO PLANUNG(stelle,bereich,wert,monat,jahr
)
VALUES(?stelle,?bereich,?wert,?monat,?jahr
)

Aber leider erfolglos,wäre ja auch zu einfach,wo soll der her wissen welche werte die variablen haben...

Ist mein vorhaben so überhaupt zu realisieren?

MrSpock 5. Apr 2004 18:26

Re: Eine von einer Prozedur stammende datenmenge ändern
 
Hallo Nightfly,

welche Datenbank nutzt du denn?

Mir ist außerdem nicht klar, was du genau vorhast. Nach einem Aufruf der Procedure mittels SELECT erhälst du eine Datenmenge mit den Feldern BEREICH, BEZ, ALLES, JAN, ..., DEZ. Die Monatswerte sind Summen aus der Tabelle Planung. Jetzt willst du diese Summen überschreiben!? Was soll denn dann passieren?

Nightfly 5. Apr 2004 22:04

Re: Eine von einer Prozedur stammende datenmenge ändern
 
die DB ist eine Firebird 1.5

Du hast schon sehr gut erkannt was ich machen will. Felder in denen eine berechnete Summe steht sollen gesperrt werden(das hab ich vergessen zu erwähnen).
Felder in denen nach dem berechnen noch ein null steht, sollen editierbar sein. In die tabelle planung soll dann ein ds eingefügt werden, mit dem eingegeben wert, dem monat (aus der spalte),dem bereich(aus derzeile) und jahr sowie stelle(als variablen verfügbar)


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:46 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz