Subject Re: [firebird-support] VIEW with parameter
Author Helen Borrie
At 10:10 PM 11/04/2006, you wrote:
>Hi,
>
>maybe it's so simple, that I missed it. I have the following view:
>
>CREATE VIEW V_SWISS_ATHLETES
>AS
>
>select A.ATHLETEID, A.LASTNAME, A.FIRSTNAME, A.GENDER, A.BIRTHDATE from
>ATHLETE A
>join CLUB C on A.CLUBID = C.CLUBID
>join CLUB CA on A.CLUBID_ALT = CA.CLUBID
>where
> (C.CLUBTYPE <= 2 and C.CLUBIDNATION = 346) or
> (CA.CLUBTYPE <= 2 and CA.CLUBIDNATION = 346)
>
>;
>
>
>Now instead of having the constant 346 for the nation, I would like that
>to be a parameter to do something like this:
>
>select * from V_SWISS_ATHLETES where NATIONID = 346
>
>
>How do I have to do that?

You need a union and you need NATIONID in the view specification:

CREATE VIEW V_SWISS_ATHLETES
(ATHLETEDID, LASTNAME, FIRSTNAME, GENDER, BIRTHDATE, NATION)
AS

select A.ATHLETEID, A.LASTNAME, A.FIRSTNAME, A.GENDER, A.BIRTHDATE,
C.CLUBIDNATION from ATHLETE A
join CLUB C on A.CLUBID = C.CLUBID
where C.CLUBTYPE <=2
UNION
select AA.ATHLETEID, AA.LASTNAME, AA.FIRSTNAME, AA.GENDER,
AA.BIRTHDATE, CA.CLUBIDNATION from ATHLETE AA
join CLUB CA on AA.CLUBID_ALT = CA.CLUBID
where CA.CLUBTYPE <=2

./heLen