I have a case where I am using a OUTER APPLY
query as below
OUTER APPLY (
SELECT TOP 1 CUSTOMER_CATEGORY
FROM [UX_VW_CUSTOMER_DETAILS] UVFS
WHERE UVFS.CUSTOMER_ID = ss.CUSTOMER_ID
) SFD
But I have new requirement where OUTER APPLY
should happen based on considering customer_category = 'General'
if present.
Pseudo code will be like as below
if (Any Item present in [UX_VW_CUSTOMER_DETAILS] with CUSTOMER_CATEGORY=="General' for the specific customer)
{
SELECT TOP 1 CUSTOMER_CATEGORY
FROM [UX_VW_CUSTOMER_DETAILS] UVFS
WHERE UVFS.CUSTOMER_ID = ss.CUSTOMER_ID
AND UVFS.CUSTOMER_CATEGORY LIKE '%General%'
}
ELSE
{
SELECT TOP 1 CUSTOMER_CATEGORY
FROM [UX_VW_CUSTOMER_DETAILS] UVFS
WHERE UVFS.CUSTOMER_ID = ss.CUSTOMER_ID
}
Can anyone suggest better way to rewrite outer apply code in efficient way.