CREATE FUNCTION "DBA"."get_eak_sumbeforevat"( in a_id_dk_earve integer, in a_id_dk_earve_sum integer )
RETURNS decimal(20,2)
BEGIN
  declare ldc_return decimal(20,2);
  select sum(cast(trim("dk_earve_ext"."text1") as decimal(20,2))) into ldc_return from "dk_earve_ext" where "dk_earve_ext"."id_dk_earve"=a_id_dk_earve and "dk_earve_ext"."id_dk_earve_sum"=a_id_dk_earve_sum and "dk_earve_ext"."parent"='InvoiceSumGroup' and "dk_earve_ext"."name"='VAT';
  if ldc_return is null then
    set ldc_return=0
  end if;
  return ldc_return;
END