Subject | Use of CASE in select statement in Storec Proc |
---|---|
Author | Erik De Laet |
Post date | 2006-01-21T09:00:01Z |
Hi,
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.
SET TERM ^^ ;
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';
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 UPPER(: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 UPPER(: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 ; ^^
----------
Erik De Laet - CEO E.De.L.Com bvba
Author of Sitestepper - the Web Maintenance
program. Visit the home of Sitestepper at www.sitestepper.com.
Programmer by choice and profession !
----------
E.De.L.Com bvba - The Software bridge to the user !
Software-, hardware en internetconsultants and
developers in Delphi, Paradox and VBA (Word, Excel en Access).
----------
Lambrechtshoekenlaan 211-2170 Merksem
(Antwerpen)-Belgiƫ-ONr:BTW BE 0460.974.682
tel: (32)3-541 77 24 - fax: (32)3-542 49 69 -
mobile: (32)475-32 99 47 - (32)475-81 67 83
web site: www.edelcom.be - www.edelcom.com - email: info@...
[Non-text portions of this message have been removed]
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.
SET TERM ^^ ;
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';
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 UPPER(: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 UPPER(: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 ; ^^
----------
Erik De Laet - CEO E.De.L.Com bvba
Author of Sitestepper - the Web Maintenance
program. Visit the home of Sitestepper at www.sitestepper.com.
Programmer by choice and profession !
----------
E.De.L.Com bvba - The Software bridge to the user !
Software-, hardware en internetconsultants and
developers in Delphi, Paradox and VBA (Word, Excel en Access).
----------
Lambrechtshoekenlaan 211-2170 Merksem
(Antwerpen)-Belgiƫ-ONr:BTW BE 0460.974.682
tel: (32)3-541 77 24 - fax: (32)3-542 49 69 -
mobile: (32)475-32 99 47 - (32)475-81 67 83
web site: www.edelcom.be - www.edelcom.com - email: info@...
[Non-text portions of this message have been removed]