Sample procedure: determining age

The following procedure shows how easy it is to determine the age of someone or something simply using the current date and the birth date (or date of origination):

 CREATE PROCEDURE ALTER_IN_JAHREN (
    geb date)
 returns (
    alter_in_jahren integer)
 as
 declare variable geb_tt integer;
 declare variable geb_mm integer;
 declare variable geb_jj integer;
 declare variable akt_tt integer;
 declare variable akt_mm integer;
 declare variable akt_jj integer;
 declare variable hatte_schon_Geb char(1);
 begin
  /* erstellt mit der IBExpert.com Educational version*/
  geb_tt=extract(day from geb);
  geb_mm=extract(month from geb);
  geb_jj=extract(year from geb);
  akt_tt=extract(day from current_date);
  akt_mm=extract(month from current_date);
  akt_jj=extract(year from current_date);
  hatte_schon_Geb='N';
  if (geb_mm<akt_mm) then hatte_schon_Geb='J';
  else
  if ((geb_mm=akt_mm) and (geb_tt<=akt_tt)) then hatte_schon_Geb='J';
  alter_in_jahren=akt_jj-geb_jj-1;
  if (hatte_schon_geb='J') then alter_in_jahren=alter_in_jahren+1;
  suspend;
 end

See also:
SELECT
DDL - Data Definition Language
Stored procedure and trigger language
Writing stored procedures and triggers
Stored procedure

back to top of page
<< Differences between recreate procedure and create or alter procedure | IBExpert | Procedure using the SUBSTRING() function (Susbstr procedure) >>