假設你有另一個表cmpTable (cmpId, cmpFirstName, cmpLastName)
具有同等列定義和cmpID的PK存儲候選集,
select cmpId
CASE 4 * eqID + 2 * eqFN + eqLN
WHEN 7 THEN 'Enrolled'
WHEN 5 THEN 'FirstName Does Not Match'
WHEN 6 THEN 'LastName Does Not Match'
WHEN 4 THEN 'FirstName & LastName Does Not Match'
ELSE 'Not Enrolled'
END
from (
select cmpId
, CASE ID WHEN cmpID THEN 1 ELSE 0 END eqID
, CASE FirstName WHEN cmpFirstName THEN 1 ELSE 0 END eqFN
, CASE LastName WHEN cmpLastName THEN 1 ELSE 0 END eqLN
from table t1
join cmpTable ct ON (ct.cmpID = t1.ID)
union
select cmpId
, 0 eqID
, 0 eqFN
, 0 eqLN
from cmpTable
where not exists (
select 1
from table t2
where t2.ID = cmpID
)
)
;
謝謝大家爲您的迴應。我決定參加聯盟路線......這是最簡單的。 – 2013-04-23 19:31:42