Subject | conditional selects in a SP |
---|---|
Author | Alan.Davies@aldis-systems.co.uk |
Post date | 2007-11-19T11:25:23Z |
Hi, I don't know if this can be done, but basically I want to select
one single record, or all relevant records in a database. I do this as
follows but there is a lot of duplicate coding (and, therefore, more
chance of errors) This is a cut-down version, if they were all this
simple I wouldn't bother:
CREATE PROCEDURE HAULIERCHARGES (
print_all_one integer,
supphaul integer,
)
returns (
code integer,
name char(40)
amount numeric(9,2))
as
begin
if (PRINT_ALL_ONE=0) then /* One Haulier only - :HaulCode */
begin
for select H.Haul_Code,H.Haul_Name,A.amount
from Haulier H,account_charges A
where H.Haul_Code=:supphaul *** the difference ***
and A.code=H.haul_code
order by H.Haul_Name
into :Code,:Name,:Amount
do
suspend;
end
else if (PRINT_ALL_ONE=1) then /* All Hauliers */
begin
for select H.Haul_Code,H.Haul_Name,A.amount
from Haulier H,account_charges A
where A.code=H.haul_code *** the difference ***
order by H.Haul_Name
into :Code,:Name,:Amount
do
suspend;
end
end
--
Alan J Davies
one single record, or all relevant records in a database. I do this as
follows but there is a lot of duplicate coding (and, therefore, more
chance of errors) This is a cut-down version, if they were all this
simple I wouldn't bother:
CREATE PROCEDURE HAULIERCHARGES (
print_all_one integer,
supphaul integer,
)
returns (
code integer,
name char(40)
amount numeric(9,2))
as
begin
if (PRINT_ALL_ONE=0) then /* One Haulier only - :HaulCode */
begin
for select H.Haul_Code,H.Haul_Name,A.amount
from Haulier H,account_charges A
where H.Haul_Code=:supphaul *** the difference ***
and A.code=H.haul_code
order by H.Haul_Name
into :Code,:Name,:Amount
do
suspend;
end
else if (PRINT_ALL_ONE=1) then /* All Hauliers */
begin
for select H.Haul_Code,H.Haul_Name,A.amount
from Haulier H,account_charges A
where A.code=H.haul_code *** the difference ***
order by H.Haul_Name
into :Code,:Name,:Amount
do
suspend;
end
end
--
Alan J Davies