Hi

Here is a function I created in Sybase, IMHO it is very close to R:base
since R:Base set a lot of standards.

the major diffs
1. you must declare a variable before using it
2. cursor declares must be declared up front
3. you don't use "v" for varible like R:Base
4. all lines must end with a SEMI ";"

Sybase function
------ start function define ---------------
ALTER function dba.HistYTD(in vAccYear integer)
returns integer
begin
  --Stored Procedure: HistYtd (function)
  --Intended Run By: DBA and Authoized through app
  --written by: Ben Johansen
  --written on: 03-Apr-2001
  --Rev. Number 1
  --Parameters:  None
  --Summary: Recompute YTD in the History Table and store it in HISTYTD
column
  --when to run: During Every Post
  --declare variables
  declare vyr integer;
  declare vcuryr integer;
  declare vacctnbr char(12);
  declare vaccttemp char(12);
  declare vaccttype char(4);
  declare verr integer;
  declare vmcnt integer;
  declare vendmn integer;
  declare vmthnbr integer;
  declare vytd MONEY;
  declare vtcnt integer;
  declare vamt MONEY;
  --declare cursors
  declare cur_hdata dynamic scroll cursor for select Accountnbr from
dba.Acc_CHART where
      AccGD = 'D' and Active = 'Y' order by Accountnbr asc;
  --get year
  set vyr=vAccYear;
  --get Current Year
  set vcuryr=year(now(*));
  --set month number
  if vcuryr > vyr then
    set vmthnbr=month(now(*));
    if vmthnbr = 1 then
      set vendmn=13
    end if;
    if vmthnbr = 2 then
      set vendmn=14
    end if;
    if vmthnbr = 3 then
      set vendmn=15
    end if
  else
    set vendmn=month(now(*))
  end if;
  --add 1 to vendmn for while loop in hdata cursor
  set vendmn=vendmn+1;
  --------------
  --start loop--
  --------------
  open cur_hdata with hold;
  fetch next cur_hdata into vacctnbr;
  set verr=sqlcode;
  while(verr = 0) loop
    //print vacctnbr;
    set vmcnt=0;
    set vtcnt=0;
    set vytd=0.0;
    while vmcnt < vendmn loop
      select amount into vamt from dba.Acc_HISTORY where Accountnbr =
vacctnbr and month = vmcnt;
      set vytd=vytd+vamt;
      set vtcnt=vmcnt+1;
      update dba.Acc_History set HISTYTD = vytd where Accountnbr = vacctnbr
and month = vmcnt;
      set vmcnt=vmcnt+1
    end loop;
    fetch next cur_hdata into vacctnbr;
    set verr=sqlcode
  end loop;
  //print verr;
  close cur_hdata;
  return 0
end
-------end function define------------------

Just a note the above function process in just under 2 seconds on 5000 rows
and is called from tango as a direct-DBMS

Ben Johansen


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Dan Weissmann
Sent: Thursday, May 31, 2001 1:55 PM
To: [EMAIL PROTECTED]
Subject: Re: RBase Vs Power Builder


The one interesting thing I recall about Sybase was when Abacus was
abandoning RBase (Should we refer to this era as B.R>.?). An RBase developer
in Australia was urging everyone to switch to Sybase. He had arranged for
what was claimed to be a very good deal from Sybase for all Rbase
developers. What I found most intriguing was a claim he made that the
languages and overall design of the products were extremely close, and so
there would be a low learning curve. Does anyone remember seeing this
information?

I view this kind of stuff with great skepticism (one reason I don't have a
copy of Sybase collecting dust in my office), but the idea of having a sort
of Esperanto of databases (or a super-SQL, without lots of flavours), really
intrigues me. I wonder how compatible the two products really are. How close
are the languages? The systems?

Dan


Reply via email to