Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Update mit temp subselect

Empfohlene Antworten

Veröffentlicht

Hallo Forumgemeinde,

Hoffe ihr könnt mir bei diesem Problem helfen (benutze (leider) MS Access 2003):

1.Tabelle[MIS_CU]: No, Stueckpreis

2.Tabelle[MIS_PC]: No, Staffelmenge, 'Wert der PreisPos'

Ich möchte die 1.Tabelle updaten: mit der Summe aus den Preispositionen der niedrigsten Staffelmenge, gruppiert auf No und Staffelmenge

Hier mein SQL:


update MIS_CU

set MIS_CU.CU_UP =

(

  SELECT Min(Preise.stck_preis) AS stck_preis

  FROM (

      SELECT MIS_PC.PC_CU_No, Sum(MIS_PC.PC_Act) AS stck_preis

      FROM MIS_PC

      GROUP BY MIS_PC.PC_CU_No, MIS_PC.PC_QS

  ) AS Preise

  [B]WHERE MIS_CU.CU_NO = Preise.PC_CU_No[/B]

  GROUP BY Preise.PC_CU_No

);

PS. Der Subselect funktioniert einwandfrei:

  SELECT Min(Preise.stck_preis) AS stck_preis

  FROM (

      SELECT MIS_PC.PC_CU_No, Sum(MIS_PC.PC_Act) AS stck_preis

      FROM MIS_PC

      GROUP BY MIS_PC.PC_CU_No, MIS_PC.PC_QS

  ) AS Preise

  GROUP BY Preise.PC_CU_No

Ich hoffe ich habe mich verständlich ausgedrückt.

Danke für jeden Tipp.

Gruß

*push*

Die Frage ist:

Warum funktioniert der Updatebefel nicht, obwohl der Select klappt?

Hier mein Select:

SELECT MIS_CU.*,

  (SELECT Min(Preise.stck_preis) AS stck_preis

   FROM (

         SELECT MIS_PC.PC_CU_No, Sum(MIS_PC.PC_Act) AS stck_preis

         FROM MIS_PC

         GROUP BY MIS_PC.PC_CU_No, MIS_PC.PC_QS

         ) AS Preise

   WHERE MIS_CU.CU_NO = Preise.PC_CU_No

   GROUP BY Preise.PC_CU_No

   )

FROM MIS_CU

Gruß

Die Frage ist:

Warum funktioniert der Updatebefel nicht, obwohl der Select klappt?

Hier mein Select:

SELECT MIS_CU.*,

  (SELECT Min(Preise.stck_preis) AS stck_preis

   FROM (

         SELECT MIS_PC.PC_CU_No, Sum(MIS_PC.PC_Act) AS stck_preis

         FROM MIS_PC

         GROUP BY MIS_PC.PC_CU_No, MIS_PC.PC_QS

         ) AS Preise

   WHERE MIS_CU.CU_NO = Preise.PC_CU_No

   GROUP BY Preise.PC_CU_No

   )

FROM MIS_CU

Gruß

- Und welche Fehlermeldung kommt ? Wenn du hier Hilfe willst, musst du dein Problem schon etwas spezifischer Beschreiben.

Der Select klappt wunderbar:

Alle Spalten aus MIS_CU werden ausgegeben und noch die zusätzlich selektierte Spalte (Preis pro Stueck), welche beim Update in MIS_CU.CU_UP geschrieben werden soll.

Soweit also alles bestens. Das Problem beginnt jetzt beim Updatebefehl.

Wenn ich den SQL so ausführe:

update MIS_CU

set MIS_CU.CU_UP =

(

  SELECT Min(Preise.stck_preis) AS stck_preis

  FROM (

      SELECT MIS_PC.PC_CU_No, Sum(MIS_PC.PC_Act) AS stck_preis

      FROM MIS_PC

      GROUP BY MIS_PC.PC_CU_No, MIS_PC.PC_QS

  ) AS Preise

  WHERE MIS_CU.CU_NO = Preise.PC_CU_No

  GROUP BY Preise.PC_CU_No

);
... fehlt meiner Meinung nach die Where-Klausel, in der ich sage, welche MIS_CU.CU_NO mit dem stck_preis geupdatet werden soll. Es erscheint die Fehlermeldung (liegt aber nicht an Zugriffsrechten): "Operation muss eine aktualisierbare Abfrage verwenden" Führe ich das ganze so aus:
update MIS_CU

set MIS_CU.CU_UP =

(

  SELECT Min(Preise.stck_preis) AS stck_preis

  FROM (

      SELECT MIS_PC.PC_CU_No, Sum(MIS_PC.PC_Act) AS stck_preis

      FROM MIS_PC

      GROUP BY MIS_PC.PC_CU_No, MIS_PC.PC_QS

  ) AS Preise

  WHERE MIS_CU.CU_NO = Preise.PC_CU_No

  GROUP BY Preise.PC_CU_No

)

[B]where MIS_CU.CU_NO = Preise.PC_CU_NO[/B]
... liegt Preise.PC_CU_NO außerhalb des Gültigkeitsbereiches. Der Update-String wär meiner Ansicht nach so korrekt:
UPDATE MIS_CU

SET MIS_CU.CU_UP =

   (SELECT MIN(Preis.stck_preis) AS stck_preis

    FROM (SELECT MIS_PC.PC_CU_No, SUM(MIS_PC.PC_Act) AS stck_preis

          FROM MIS_PC

          GROUP BY MIS_PC.PC_CU_No, MIS_PC.PC_QS

          ) AS Preis

    WHERE MIS_CU.CU_NO = Preis.PC_CU_No

    GROUP BY Preis.PC_CU_No

    )

WHERE MIS_CU.CU_NO IN

      (SELECT MIS_PC.PC_CU_No

       FROM MIS_PC

       GROUP BY MIS_PC.PC_CU_No

      )

Leider aber selbe Fehlermeldung:

"Operation muss eine aktualisierbare Abfrage verwenden"

Hat evtl. jemand einen Tipp?

Schon mal recht herzlichen Dank für eure Bemühungen.

Gruß,

batze

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.