complex view query with multiple lookups [message #636342] |
Wed, 22 April 2015 04:23 |
natrajdreams
Messages: 10 Registered: January 2009
|
Junior Member |
|
|
I have four tables named HOLDER,ADDRESS,CLNT,DETAIL.
ADDRESS table having columns ST_ADDR1,CITY,STATE,ZIPCODE.
we need to write a view on ADDRESS table for the above columns according the logic given by below for each column.
ST_ADDR1
-----------------
Join HOLDER.NUM = ADDRESS.KEY_ID
AND ADDRESS.ADDR_TYPE = 'LA' then
take HOLDER.L_ID
IF HOLDER.L_ID > 0 then look up on DETAIL
CLNT.L_ID = DETAIL.L_CD
AND CLNT.I_CD = DETAIL.I_CD
AND DETAIL.DT <= SYSDATE
AND (DETAIL.EXP_DT is null or DETAIL.EXP_DT >= SYSDATE) then
take DETAIL.AD_DIS
CITY
------------
Join HOLDER.NUM = ADDRESS.KEY_ID
AND ADDRESS.ADDR_TYPE = 'LA' then
take HOLDER.L_ID
IF HOLDER.L_ID > 0 then look up on DETAIL
CLNT.L_ID = DETAIL.L_CD
AND CLNT.I_CD = DETAIL.I_CD
AND DETAIL.DT <= SYSDATE
AND (DETAIL.EXP_DT is null or DETAIL.EXP_DT >= SYSDATE) then
take DETAIL.CITY_D
STATE
------------
Join HOLDER.NUM = ADDRESS.KEY_ID
AND ADDRESS.ADDR_TYPE = 'LA' then
take HOLDER.L_ID
IF HOLDER.L_ID > 0 then look up on DETAIL
CLNT.L_ID = DETAIL.L_CD
AND CLNT.I_CD = DETAIL.I_CD
AND DETAIL.DT <= SYSDATE
AND (DETAIL.EXP_DT is null or DETAIL.EXP_DT >= SYSDATE) then
take DETAIL.STATE_CD
ZIPCODE
--------------
Join HOLDER.NUM = ADDRESS.KEY_ID
AND ADDRESS.ADDR_TYPE = 'LA' then
take HOLDER.L_ID
IF HOLDER.L_ID > 0 then look up on DETAIL
CLNT.L_ID = DETAIL.L_CD
AND CLNT.I_CD = DETAIL.I_CD
AND DETAIL.EFF_DT <= SYSDATE
AND (DETAIL.EXP_DT is null or DETAIL.EXP_DT >= SYSDATE) then
take DETAIL.ZIP_CD
Kindly help me to write a view by using the above logic mentioned.
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: complex view query with multiple lookups [message #636377 is a reply to message #636350] |
Wed, 22 April 2015 08:51 |
natrajdreams
Messages: 10 Registered: January 2009
|
Junior Member |
|
|
Hi Lalit,
I have tried the below query.. Please correct me.
CREATE VIEW P_VIEW
AS
SELECT CASE WHEN holder.l_id > 0
THEN detail.ad_dis
ELSE address.st_addr1 END AS addr1
, CASE WHEN holder.l_id > 0
THEN detail.city_d
ELSE address.city END AS city
, CASE WHEN holder.l_id > 0
THEN detail.state_cd
ELSE address.state END AS state
, CASE WHEN holder.l_id > 0
THEN detail.zip_cd
ELSE address.zipcode END AS zipcode
FROM holder
LEFT OUTER
JOIN address
ON address.key_id = holder.num
AND address.addr_type='LA'
LEFT OUTER
JOIN clnt
ON clnt.l_id = holder.l_id
LEFT OUTER
JOIN detail
ON detail.l_cd = clnt.l_cd
AND detail.i_cd = clnt.i_cd
AND DETAIL.DT < sysdate
AND (
detail.exp_dt IS NULL
OR detail.exp_dt >= SYSDATE
)
*BlackSwan added {code} tags. Please do so yourself in the future. http://www.orafaq.com/forum/t/174502/
[Updated on: Wed, 22 April 2015 09:02] by Moderator Report message to a moderator
|
|
|
|
|
Re: complex view query with multiple lookups [message #636387 is a reply to message #636377] |
Wed, 22 April 2015 09:17 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
natrajdreams wrote on Wed, 22 April 2015 14:51Hi Lalit,
I have tried the below query.. Please correct me.
Lets be clear here - we know nothing about your system other than what you've told us.
We don't know the structure of the tables.
We don't know the relationship between the tables.
We don't know what data you have.
We don't know if your view gives an error or the wrong result.
We don't know what the correct result would be.
You need to supply a lot more details for anyone to be able to help you.
|
|
|