0
我一直在嘗試將開關添加到以下腳本中。
如果@IgnoreExclusions = 1
那麼我不想排除Controltb_AssocAccounts_ExcludedSurnameDOB
或Controltb_AssocAccounts_ExcludedDOB
中的任何值?將開關添加到WHERE clausse
我已經包含了我的一個嘗試,但我不認爲這是非常可讀的,而且我不確定它是否可靠地工作,因爲NULL
可能是排除列表中的一個值。
DECLARE @IgnoreExclusions TINYINT = 1;
SELECT ua.UserAccountKey,
FROM #Accounts x
INNER JOIN WH.dbo.vw_DimUserAccount ua
ON
(--surname and DOB need to match
x.Surname = ua.Surname AND
x.DOB = ua.DOB
)
AND
x.UserAccountKey <> ua.UserAccountKey
WHERE EXISTS
(
SELECT x.Surname, x.DOB
EXCEPT
SELECT ExcludedSurname,ExcludedDOB
FROM WH.dbo.Controltb_AssocAccounts_ExcludedSurnameDOB
)
AND
EXISTS
(
SELECT x.DOB
--SELECT CASE WHEN @IgnoreExclusions = 1 THEN NULL ELSE x.DOB END --<<<<ATTEMPT
EXCEPT
SELECT ExcludedDOB
FROM WH.dbo.Controltb_AssocAccounts_ExcludedDOB
)
GROUP BY ua.UserAccountKey;
+1 look bob on - I'll give it a go – whytheq 2013-03-12 18:41:22