我有以下查询:执行查询时,我得到了很多ad.Branch的结果,包括106804。如果我删除BOR.SSN和COB.SSN之类的,只是离开分支,仅返回106804条记录,这是所需的结果。因此,我相信like语句是导致问题的原因。
declare @Social varchar(5);
set @social = '%####'
SELECT
ABC.AccountNumber
FROM gcc.AccountDailyFact ABC
JOIN gcc.Today T ON ABC.CalendarDate = T.Today
JOIN gcc.ADReference AD ON ABC.ADReferenceRowId = AD.ADReferenceRowId
JOIN gcc.CDAccountData BOR ON ABC.BDLeaseHolderRowId = BOR.CDAccountDataRowId
JOIN gcc.CDAccountData COB ON ABC.CoBDLeaseHolderRowId = COB.CDAccountDataRowId
JOIN gcc.VDAssetFile VD ON ABC.VDAssetFileRowID = VD.VDAssetFileRowID
其中BOR.SSN如@social或COB.Ssn如@social和ad.Branch in ('106804')
答案 0 :(得分:1)
我认为您只需要括号即可
WHERE (BOR.SSN like @social or COB.Ssn like @social) and
ad.Branch in ('106804')