我的目标是显示只有bofa撤回的声明。当我做我的代码它只给我2,或在工作它给我索赔110329100082有bofa w / ds但我只想要声明谁的争议只是美国银行。最后我想要的是:
CLAIMNbr 121104101432, 130101104813, 130202100467, 130326100004
使用声明 GO
SELECT A.ClaimNbr
FROM dbo.CCMSClaimCore A
LEFT JOIN dbo.CCMSTransactionCore B
ON A.ClaimNbr = B.ClaimNbr
WHERE A.Frdtyp IN('Counterfiet', 'Counterfeit', 'CardSecure')
AND B.merchantNm = 'BKOFAMERICA%WITHDR%'
OR A.ClaimTypCd = 'ATMWP'
下载一些代码放入db
CREATE TABLE CCMSClaimCore
(
ClaimNbr varchar(50) Not NUll,
ClaimTypCd varchar(8) Not Null,
FraudTyp varchar(15) Not Null,
)
INSERT INTO CCMSClaimCore (ClaimNbr, ClaimTypCd, FraudTyp)
VALUES (110329100082, 'FATMD', 'CardSecure')
INSERT INTO CCMSClaimCore (ClaimNbr, ClaimTypCd, FraudTyp)
VALUES (110330101000, 'FATMD', 'CardSecure')
INSERT INTO CCMSClaimCore (ClaimNbr, ClaimTypCd, FraudTyp)
VALUES(121104101432, 'FATMD', 'Counterfeit')
INSERT INTO CCMSClaimCore (ClaimNbr, ClaimTypCd, FraudTyp)
VALUES(130101104813, 'ATMWP', 'CardSecure')
INSERT INTO CCMSClaimCore (ClaimNbr, ClaimTypCd, FraudTyp)
VALUES(130101109216, 'FATMD', 'Counterfiet')
INSERT INTO CCMSClaimCore (ClaimNbr, ClaimTypCd, FraudTyp)
VALUES(130202100467, 'ATMWP', 'Counterfiet')
INSERT INTO CCMSClaimCore (ClaimNbr, ClaimTypCd, FraudTyp)
VALUES(130326100004, 'FATMD', 'CardSecure')
Create table CCMSTransactionCore
(
ClaimNbr varchar(12) Not null ,
DisputeNbr varchar(12) Not Null ,
MerchantNm varchar(50) Not Null
)
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(110329100082, 110329200082, 'BKOFAMERICA ATM 03/28 #000007450 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(110329100082, 110329200083, 'MPX1 03/27 #000918793 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(110329100082, 110329200084, 'BKOFAMERICA ATM 03/28 #000007450 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(110330101000, 110330201000, 'PNC 01/17 #300918765 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(121104101432, 121104201432, 'BKOFAMERICA ATM 01/06 #000007450 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(121104101432, 121104201433, 'BKOFAMERICA ATM 01/06 #000007450 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(130101104813, 130101104813, 'BKOFAMERICA ATM 12/06 #000007450 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(130101109216, 130101207892, 'MPX1 03/27 #000918793 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(130101109216, 130101207893, 'PNC 03/24 #300918765 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(130101109216, 130101207894, 'BKOFAMERICA ATM 03/06 #000007450 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(130202100467, 130202200467, 'BKOFAMERICA ATM 02/14 #000007450 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(130202100467, 130202200468, 'BKOFAMERICA ATM 02/14 #000007450 WITHDRWL')
INSERT INTO CCMSTransactionCore (ClaimNbr, DisputeNbr, MerchantNm)
VALUES(130326100004, 130326200004, 'BKOFAMERICA ATM 03/08 #000007450 WITHDRWL')
答案 0 :(得分:1)
我认为您要说的是,您希望声明数字,其中相关表格的商家名称为BKOFAMERICA%WITHDR%,仅 BKOFAMERICA%WITHDR%。如果它有BOFA,例如PNC,那么不要显示该索赔号,对吧?试试这个:
Use Claim
GO
;WITH BOFAOnlyClaims AS (
SELECT B.ClaimNbr
FROM dbo.CCMSTransactionCore B
GROUP BY B.ClaimNbr
HAVING MAX(CASE WHEN B.merchantNm = 'BKOFAMERICA%WITHDR%' THEN 1 ELSE 2 END) = 1
)
SELECT A.ClaimNbr
FROM dbo.CCMSClaimCore A
JOIN BOFAOnlyClaims BOC ON A.ClaimNbr = BOC.ClaimNbr
WHERE A.Frdtyp IN('Counterfiet', 'Counterfeit', 'CardSecure')
OR A.ClaimTypCd = 'ATMWP';