multiple table selection is this possible - newbie question ?

multiple table selection is this possible - newbie question ?

am 02.06.2006 11:02:02 von CobraStrikes

Hi All,
I hope I have explained this well enough for you to understand what I am trying to do.
I table A

Code,CodeType

depending on CodeType it needs info From Different Tables, How can I do this in SELECT
statement?

Select A.Code,A.CodeType,B.NameDesc,C.NameDesc,D.NAmeDesc FROM A
if CodeType=1 then return B.NameDesc FROM B
else if CodeType=2 then return C.NameDesc FROM C
else if CodeType=3 then return D.NameDesc FROM D

how can do the above ?

Many Thanks

Re: multiple table selection is this possible - newbie question ?

am 02.06.2006 16:03:24 von Rich R

wrote in message
news:1149238922.24858.0@proxy00.news.clara.net...
> Hi All,
> I hope I have explained this well enough for you to understand
what I am trying to do.
> I table A
>
> Code,CodeType
>
> depending on CodeType it needs info From Different Tables, How can I do
this in SELECT
> statement?
>
> Select A.Code,A.CodeType,B.NameDesc,C.NameDesc,D.NAmeDesc FROM A
> if CodeType=1 then return B.NameDesc FROM B
> else if CodeType=2 then return C.NameDesc FROM C
> else if CodeType=3 then return D.NameDesc FROM D
>
> how can do the above ?
>
> Many Thanks
>
>

This will get you started:

select code,
case when codetype = 1 then
(select namedesc from b where b.code = a.code)
when codetype = 2 then
(select namedesc from c where c.code = a.code)
end namedesc
from a

Of course I'm assuming you have "code" in all of your tables. Are tables
b,c,etc. subtypes of A?

Rich