SELECT
ERI.ATTACK_CASE_ID,
LRM.REF_VALUE AS ATTACK_CASE_STATUS,
WDR.RESTRICTION_NAME,
LL.USER_LABEL AS ***RESTRICTION_STATUS***,
WSRI.RESTRICTION_DATE,
CASE NVL(ERI.IS_PRIMARY, 0) WHEN 0 THEN 'No' ELSE CASE ERI.IS_PRIMARY WHEN 1 THEN 'Yes' ELSE 'No' END END AS PRIMARY
FROM ALERT A
LEFT OUTER JOIN ENTITY_RESTRICTION_INFO ERI ON A.ALERT_KEY=ERI.ENTITY_KEY
LEFT OUTER JOIN LK_REFERENCE_MAPPING LRM ON LRM.REF_KEY= TO_CHAR(ERI.ATTACK_CASE_STATUS)
LEFT OUTER JOIN LK_REFERENCE_CATEGORY LRG ON LRM.LK_REFERENCE_CATEGORY_ID = LRG.ID
AND LRG.CATEGORY_CODE = 'DD'
AND LRG.SUB_CATEGORY_CODE='ATTACK_STATUS_ID_NAME'
LEFT OUTER JOIN WNORKOM_DD_RESTRICTION WDR ON ERI.RESTRICTION_ID=WDR.RESTRICTION_ID
LEFT OUTER JOIN WNORKOM_SAR_RESTRICT_INFO WSRI ON WSRI.RESTRICTION_ID=ERI.RESTRICTION_ID
*LEFT OUTER JOIN LK_LOOKUPS LL ON LL.CODE=**WSRI.RESTRICTION_STATUS***
WHERE A.ALERT_KEY=121234
AND ERI.ATTACK_CASE_ID='PP-123-0980'
AND LL.TYPE=9502
The above query returns me all the records when there is some value in WSRI.RESTRICTION_STATUS
However, it returns NO RECORDS when WSRI.RESTRICTION_STATUS = NULL.
What can I add/change in above query so that LL.USER_LABEL = ‘Unknown’ when WSRI.RESTRICTION_STATUS = NULL. For your information, there is no value ‘Unknown’ in LK_LOOKUPS table. This is something I want to return as an independent string when WSRI.RESTRICTION_STATUS = NULL. Adding a record to LK_LOOKUPS table with LL.CODE=NULL and LL.USER_LABEL=’Unknown’ can mess up things so please help me passing it independently in the query.
Thanks in advance.
It sounds you simply need to move the criteria
LL.Type = 9502into the Left Join and use Coalesce in the Select clause. Also, since you are applying criteria to a column in theEntity_Restriction_Infotable from the Where clause, you have transformed the Left Join to this table into an Inner Join and thus, you might as well use an Inner Join.