V4RB: Question about SQL

Claudius Sailer Claudius at sailer-online.de
Sat Jan 1 17:44:44 CST 2005


Hi,

I have 2 Functions which calculates 2 values out of one table. Is it 
possible to bring this with valentina 2 in one function in one 
SQL-Statement?
The problem is, that the values in every function could by bigger then 
RB integer but the diffence of both normally never.

IMHO I think following would bring solution, when it will work in V4RB 
2.X

SELECT
( SELECT SUM(Betrag)
    FROM Buchungen
   WHERE Ziel_Konto=KontoRecID
   AND BDatum>'StartDatum'
  AND BDatum<='Enddatum'
   )
-
( SELECT SUM(Betrag)
    FROM Buchungen
    WHERE Herk_Konto= KontoRecID
     AND BDatum>'StartDatum'
      AND BDatum<='Enddatum'
   )

But with V4RB 1.10 this wouldn't work or is this wrong?

Thanks for help


Claudius


FUNCTION 1
   //Hier werden die Einnahmen ermittelt
     Dim CurBuchungen as VCursor
     //Einnahmen
   SQLString="SELECT SUM(Betrag)"
   SQLString=SQLString+" FROM Buchungen"
   SQLString=SQLString+ " WHERE Ziel_Konto= "+KontoRecID
   if NOT CheckLeer(Startdatum) then
     SQLString=SQLString+ " AND BDatum>'"+StartDatum+"'"
   end if
   if NOT checkLeer(Enddatum) then
     SQLString=SQLString+ " AND BDatum<='"+Enddatum+"'"
   end if

   CurBuchungen=meineDatenbank.SQLselect(SQLString, kV_Server, 
kV_NoLocks, kV_Random)
   if CurBuchungen<>NIL   then
     CurBuchungen.CurrentPosition=1
     return CurBuchungen.LLongField(1).value
   else
     return 0
   end if

FUNCTION 2
   //Hier werden die Ausgaben ermittelt
     Dim CurBuchungen as VCursor
     //Ausgaben
   SQLString="SELECT SUM(Betrag)"
   SQLString=SQLString+" FROM Buchungen"
   SQLString=SQLString+ " WHERE Herk_Konto= "+KontoRecID
   if NOT CheckLeer(Startdatum) then
     SQLString=SQLString+ " AND BDatum>'"+StartDatum+"'"
   end if
   if NOT checkLeer(Enddatum) then
     SQLString=SQLString+ " AND BDatum<='"+Enddatum+"'"
   end if

   CurBuchungen=meineDatenbank.SQLselect(SQLString, kV_Server, 
kV_NoLocks, kV_Random)
   if CurBuchungen<>NIL then
     CurBuchungen.CurrentPosition=1
     return CurBuchungen.LLongField(1).value
   else
     return 0
   end if



More information about the Valentina-beta mailing list