Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

re:decode or better way

Status
Not open for further replies.

raji96

Programmer
Aug 7, 2001
64
US
I need to select from tblw few attributes based on few condition.

If the wid matches the id in tblMp and if the ind value is 'S' then i also need to select the id and desc from tbls along with the other attributes selected.
else if
wid matches with the id in tblmp but the value is 'o' then ihave to select the id and desc from the tblso table along with the attributes from tblw table.
else if
wid does not match with id in tblmp i have to select the id and desc from the tblso table along with the attributes in tblw table.


I have written the select something like this but am looking for a better way?Can this be done by using 'decode".


TblW tblMP tbls tblso
wid id f f
watt1 f id id
watt2 ind desc desc
watt3
watt4
...
...
...
watt20




Select tblW.wid,tblW.watt1,tblW.watt2,...,...,...,tblW.watt20,tbls.id,tbls.desc
from tblW,tblMP,tbls
where
tblW.wid='1234'
AND tblW.wid=tblMP.id
AND tblMP.ind='S'
AND tblmp.f =tbls.f
union
Select tblW.wid,tblW.watt1,tblW.watt2,...,...,...,tblW.watt20,tblso.id,tblso.desc
from tblW,tblMP,tblso
where
tblW.wid='1234'
AND tblW.wid=tblMP.id
AND tblMP.ind='O'
AND tblmp.f =tblso.f
union
Select tblW.wid,tblW.watt1,tblW.watt2,...,...,...,tblW.watt20,tblso.id,tblso.desc
from tblW,tblMP,tblso
where
tblW.wid='1234'
AND tblW.wid(+)=tblMP.id
AND tblMP.ind='O'
AND tblmp.f =tblso.f

thanks.

raji96
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top