Subject Re: [ib-support] SP Problem
Author Walter Neumann
Hi Lucas,
thank you for your reply.

> are you sure that STICHTAG2 (which seems to be the last day in month) is
> what you're really looking for?

yes, that is it.
>
> Are you sure that with
>
> > WHERE :STICHTAG2 >= (SELECT MAX(EA.EINTRITTSDATUM) FROM ...
>
> there's not "Eintrittsdatum" in the 2nd view which is AFTER STICHTAG2
> (thus returning no more records)?

This SP should give the number of employee, which are working (MA = employee
table, EA = table for starting [Eintrittsdatum] and ending [Austrittsdatum]
dates - more then one row for one employee)
>
> You wrote, that before using params you used TODAY.
> For which variable did you use today?

for both STICHTAG1 and STICHTAG2. With today the SP gives the number of
working employees today. This works with the same syntax fine. But now I wish
to know the number of working employees in a special month even if they
worked only 1 day.
>
> What happens if you execute (and assign the params of) this procedure
> directly in any DB-tool?

I use IBAccess, because I use linux. I tried it, but I don't know how to pass
the parameters. The syntax, descriebed in the sql docu didn't work (sql
error).
>
> Have a look at your records and decide which records you think should be
> returned and compare the fields with your SQL.
> Sometimes it helps to test with single SQL statements (enter all your
> WHERE -parts directly and see if they really return what you think
> they'll do).

It should return 4 records in my test data.

> > > >ALTER PROCEDURE "MITARB_COUNT"
> > > >(
> > > > "STICHTAG2" TIMESTAMP,
> > > > "STICHTAG1" TIMESTAMP
> > > >)
> > > >RETURNS
> > > >(
> > > > "ANZAHL" INTEGER
> > > >)
> > > >AS
> > > >DECLARE VARIABLE MAID INT;
> > > >BEGIN
> > > > ANZAHL = 0;
> > > > FOR SELECT MA.PERSONENIDINT FROM MITARBVIEW MA
> > > > WHERE :STICHTAG2 >= (SELECT MAX(EA.EINTRITTSDATUM) FROM
> > > > MITARBEINAUSVIEW
> > > >EA
> > > > WHERE ((EA.MITARBID = MA.PERSONENIDINT)
> > > > AND ((EA.AUSTRITTSDATUM IS NULL) OR (EA.AUSTRITTSDATUM >=
> > > >
> > > >:STICHTAG1))))
> > > >
> > > > INTO :MAID
> > > > DO
> > > > BEGIN
> > > > ANZAHL = ANZAHL + 1;
> > > > END
> > > > SUSPEND;
> > > >END