SQLTeam.com | Weblogs | Forums

Why is the date coming back as 10th July from this query?


#1

Select t.DiaryDate From tblDiary t inner join tblCaseDetails cd On t.Fk_RefNo = cd.PK_Refno where
t.DiaryDate < '2018-07-10' And t.AddedToDiary = 1 And t.Completed <> 1 And cd.FeeEarner ='ASM'
Or t.DiaryDate < '2018-07-10' And t.AddedToDiary = 1 And t.Completed <> 1 And cd.MedicalRefNo2 ='ASM'
Or t.DiaryDate < '2018-07-10' And t.AddedToDiary = 1 And t.Completed <> 1 And cd.CourtName ='ASM'
OR (cd.MedicalRefNo2 = 'ASM' AND t.Completed <> 1 AND (cd.MedicalSentToTPI2 ) <'2018-07-10' )
OR (cd.CourtName = 'ASM' AND t.Completed <> 1 AND (cd.SurveyCompleted )< '2018-07-10' )
or (cd.FeeEarner = 'ASM' AND t.Completed <> 1 AND (cd.DiaryDate ) < '2018-07-10')

	order by t.DiaryDate DESC

Results returned

2018-07-09 00:00:00.000
2018-07-09 00:00:00.000
2018-07-09 00:00:00.000
2018-07-09 00:00:00.000
2018-07-09 00:00:00.000
2018-07-10 00:00:00.000


#2

Operator precedence. The ANDs are of higher precedence than the ORs.