各位大蝦幫我check下看什么地方出錯
select distinct top 100 ent.* from tblDataEntry as ent,CaseAction as ca,DunningCode as dc,TblAddress as ad,tblBankList as bl where
ent.[Our-Ref-No] = ca.[CaseRef]
and ent.[Our-Ref-No]=ad.[Our-Ref-No] and ent.[Our-Ref-No] = ad.CaseRef
and if((lower(ent.[Special-Code-3])='EARLY')or(lower( ent.[Special-Code-3])='fresh'))
begin
and(datediff(day,ent.[Receive-Date],getdate()))>51
and(datediff(day,ent.[Last-Pay-Date],getdate()))>51
and(datediff(day,ad.TransferDate,getdate()))>51
end
else
if((lower(ent.[Special-Code-3])<>'EARLY')and(lower( ent.[Special-Code-3])<>'fresh'))
begin
and(datediff(day,ent.[Receive-Date],getdate()))>60
and(datediff(day,ent.[Last-Pay-Date],getdate()))>60
and(datediff(day,ad.TransferDate,getdate()))>60
end
Server: Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'if'.
Server: Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'and'.
Server: Msg 156, Level 15, State 1, Line 14
Incorrect syntax near the keyword 'and'.