我有一个使用OUTER APPLY
如下查询的情况
OUTER APPLY (
SELECT TOP 1 CUSTOMER_CATEGORY
FROM [UX_VW_CUSTOMER_DETAILS] UVFS
WHERE UVFS.CUSTOMER_ID = ss.CUSTOMER_ID
) SFD
但是我有新的要求,如果存在的话,OUTER APPLY
应该在哪里发生。customer_category = 'General'
伪代码如下
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
}
任何人都可以建议以有效方式重写外部应用代码的更好方法。