1

When trying to update to include a price in the previous made table Abonnement I get the error code mentioned in the title. I looked around on the net but it seems my syntax is correct?

SET SQL_SAFE_UPDATES=0;

DELETE FROM Abonnement;
DELETE FROM AbonnementType;

INSERT INTO AbonnementType(beginDatum,eindDatum,type)
VALUES("2013/1/1","2013/1/1","DAGPAS");

INSERT INTO Abonnement(betaald,AbonnementType_ATypeId,FietsType_FType,Klant_klantId,Code,Wachtwoord)
VALUES(false,(SELECT MAX(ATypeId) FROM AbonnementType),1,1,"test","test");

UPDATE Abonnement as a
JOIN FietsType AS af ON a.FietsType_FType = af.FType
JOIN AbonnementType AS at ON a.AbonnementType_ATypeId = at.ATypeId
SET a.prijs = af.Prijs * (at.eindDatum + at.beginDatum)
ORDER BY AbonnementId DESC
LIMIT 1;

2 Answers2

0

Have you tried using the WITH object?
With updateSyn As ( ... )
Update updateSyn set ...

SQL Server: UPDATE a table by using ORDER BY

Community
  • 1
  • 1
mmmmmpie
  • 2,908
  • 1
  • 18
  • 26
0

I used a workaround and now it does what is has to do.

UPDATE Abonnement as a
JOIN FietsType AS af ON a.FietsType_FType = af.FType
JOIN AbonnementType AS at ON a.AbonnementType_ATypeId = at.ATypeId
JOIN (SELECT MAX(AbonnementId) as max_id FROM Abonnement) as aa ON a.AbonnementId = aa.max_id
SET a.prijs = af.Prijs * (at.eindDatum + at.beginDatum)