Subject Re: [firebird-support] Re: Old-style left join
Author Kjell Rilbe
ainpoissee wrote:

> --- In firebird-support@yahoogroups.com, Kjell Rilbe
> <kjell.rilbe@a...> wrote:
>>Not quite true I believe. But outer joins require "union" queries. No
>>time to give any specifics right now - look it up!
>
>
> You mean something like
>
> SELECT
> RTG.Kuupaev,
> RTG.PaH,
> RTG.OhH,
> RTG.OoH,
> RTG.NormH,
> RTG.UusVah,
> RTG.VahPaevi,
> Vah.Nimi,
> Vah.AlgKell,
> CAST(RTG.Kuupaev + Vah.AlgKell+(Vah.Kestus/1440e0) AS TIME) AS LopKell
> FROM RepToolepinguGraafik(2005, 3, 5)RTG, TAB_Vahetus Vah
> WHERE(Vah.UID = RTG.Vahetus)
> UNION
> SELECT
> RTG.Kuupaev,
> RTG.PaH,
> RTG.OhH,
> RTG.OoH,
> RTG.NormH,
> RTG.UusVah,
> RTG.VahPaevi,
> NULL,NULL,NULL
> FROM RepToolepinguGraafik(2005, 3, 5)RTG
> WHERE(RTG.Vahetus IS NULL)
>
> This raises "Data type unknown" error. If I remove 3 last fields
> (which are NULL in second query) it runs and seems to give result set
> I need... how to write second part of the union so it returns NULL for
> last 3 fielts?
> I'm using FB 1.5.0.429

Not quite. In the second query you're trying to select records where
RTG.Vahetus is null. I assume that field is a PK and not very likely to
be null. Anyway, it's not what you want. You want those records from RTG
for which no matching Vah record exists. Try again.

Kjell
--
--------------------------------------
Kjell Rilbe
Adressmarknaden AM AB
E-post: kjell.rilbe@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64