Re: Help with dynamic case select?



kimberly.shaffer@xxxxxxxxx wrote:

select ta.field_name1,
CASE ta.fieldname2
select tb.fieldname2, tb.fieldname3 from TBL_b tb
when ta.fieldname2 = tb.fieldname2 then tb.fieldname3
else 'unknown, please look up'
end as "Field_Name"
from
TBL_a ta
;

I am trying to pull a case select statement without having to type a
long huge when...else statement. Thanks!
Is this possible? Can someone point me towards what to look for?

Your CASE is hard to understand, but there's probably a shortcut for it, COALESCE:
COALESCE((select tb.fieldname3 from TBL_b tb
where ta.fieldname2 = tb.fieldname2)
, 'unknown, please look up') as "Field_Name"

or write an Outer Join:
select
ta.field_name1,
coalesce(tb.fieldname3, 'unknown, please look up') as "Field_Name"
from TBL_a ta left join TBL_b tb
on ta.fieldname2 = tb.fieldname2

Dieter
.



Relevant Pages

  • Re: outer Join and NULL values...?!?!!!
    ... (and why can't the Query designer give me a clue/ability to do that more ... ...in an outer join = "No Match"? ... ...BUT I still get 15 records qualifying to be inserted into Table C ... Null sort of means Unknown. ...
    (microsoft.public.access.queries)
  • Re: outer Join and NULL values...?!?!!!
    ... If you want a null matching any thing: ... ...in an outer join = "No Match"? ... separate query to handle just those records? ... Null sort of means Unknown. ...
    (microsoft.public.access.queries)
  • Re: outer Join and NULL values...?!?!!!
    ... ....in an outer join = "No Match"? ... To avoid importing duplicate records I am joining tables B and C in my query ... ...BUT I still get 15 records qualifying to be inserted into Table C from ... Null sort of means Unknown. ...
    (microsoft.public.access.queries)
  • Re: Front end HELP
    ... the Fleetwood has 79,000 on it previous to 35,000 service is unknown does ... not seem to pull left or right ... My Georgie Boy only had 50,000 on it and it wandered all over the road when ...
    (rec.outdoors.rv-travel)
  • Re: You find an unknown (to you) book
    ... You find an unknown book by an author you like. ... the authors that you pull out your charge card then and there? ... (Remove "pants" spamblock to send e-mail) ...
    (rec.arts.sf.written)