Subject | Re: [firebird-support] Use of CASE in select statement in Storec Proc |
---|---|
Author | Helen Borrie |
Post date | 2006-01-21T11:08:25Z |
At 10:00 AM 21/01/2006 +0100, you wrote:
expression here is UPPER(:TAAL), which you can eliminate from the loop:
>Hi,Expressions are evaluated once for every record, of course. The costly
>
>The stored proc below works, but I am just curious.
>Depending on a parameter I want to return only
>one ..OMSCHRIJVING.. field (btw OMSCHRIJVING =
>DESCRIPTION in Dutch), so I have written a CASE construct.
>Is the for select statement only evaluated once ? Or once for every record.
expression here is UPPER(:TAAL), which you can eliminate from the loop:
>SET TERM ^^ ;TAAL = UPPER(TAAL);
>CREATE PROCEDURE P_TEST (
> DATUMSELECTIE Char(1),
> TAAL Char(2))
> returns (
> VANDATUM Date,
> TOTDATUM Date,
> ...
> SCHLOK_AANTAL_TAFELS Integer,
> SCHLOK_LOKAAL_OMSCHRIJVING VarChar(32),
> CURSUS_PICTOGRAM VarChar(16),
> CURSUS_OMSCHRIJVING VarChar(255))
>AS
>declare variable dt1 date;
>declare variable dt2 date;
>
>begin
> dt1 = '01/01/1900';./h
> dt2 = '12/31/2199';
> if (DATUMSELECTIE = 'T') /* toekomst */
> then dt1 = 'TODAY';
> if (DATUMSELECTIE = 'V') /* verleden */
> then dt2 = 'TODAY';
>
> /* code */
> for select VANDATUM,
> TOTDATUM,
> ...
> SCHLOK_AANTAL_TAFELS,
> CASE :TAAL
> WHEN 'FR' THEN SCHLOK_LOKAAL_OMSCHRIJVING__FR
> WHEN 'EN' THEN SCHLOK_LOKAAL_OMSCHRIJVING__EN
> WHEN 'GE' THEN SCHLOK_LOKAAL_OMSCHRIJVING__GE
> ELSE SCHLOK_LOKAAL_OMSCHRIJVING__NL
> END,
> CURSUS_PICTOGRAM,
> CASE :TAAL
> WHEN 'FR' THEN CURSUS_OMSCHRIJVING__FR
> WHEN 'EN' THEN CURSUS_OMSCHRIJVING__EN
> WHEN 'GE' THEN CURSUS_OMSCHRIJVING__GE
> ELSE CURSUS_OMSCHRIJVING__NL
> END
> from V_CURSUS_LIST
> where (VanDatum between :dt1 and :dt2)
> into :VANDATUM,
> :TOTDATUM,
> ...
> :SCHLOK_AANTAL_TAFELS,
> :SCHLOK_LOKAAL_OMSCHRIJVING,
> :CURSUS_PICTOGRAM,
> :CURSUS_OMSCHRIJVING
> do
> begin
> suspend;
> end
>end
>^^
>SET TERM ; ^^