There are three tables in the project (order, consists of and the article). I am trying to calculate the total amount of the order and return this value through a function for later use. The following code works and gives the total amount of the order:
select sum(Sub.LineItemSum) as gesamtsumme from ( select besteht_aus.ArtikelID, ArtikelAnzahl*Artikel.Preis as LineItemSum From besteht_aus inner join Artikel where besteht_aus.ArtikelID = Artikel.ArtikelID and BestellID = 2) Sub But if I try to shove this piece of code into a function, I get an error.
create or replace function gesamtsumme (@BestellID integer) returns money begin declare @summe money set @summe = (select sum(Sub.LineItemSum) as insgesamt from ( select besteht_aus.ArtikelID, ArtikelAnzahl*Artikel.Preis as LineItemSum From besteht_aus inner join Artikel where besteht_aus.ArtikelID = Artikel.ArtikelID and BestellID = @BestellID) Sub) return @summe end I suspect that set simply does not cope with a subquery. Tell me, please, what is the error and how to fix it.
return (select sum(Sub.LineItemSum) ...)- MaxUselect ... into переменнаяusually used, orselect переменная:=sum ....if it is suddenly MySQL - Mike