I am trying to get Dates from RepDailyInfo table when the RepDailyCollection.IsReceived = 0 and when the RepDailyCollection does have a record for that particular RepDailyInfoID. Is this possible in sql server 2005?
Select distinct RepDailyInfo.Date
from RepDailyInfo
left outer join RepDailyCollection c
on c.RepDailyInfoID = RepDailyInfo.RepDailyInfoID
where c.IsReceived = 0
or c.IsReceived = null
Move the conditions into the
ONclause of the join, because otherwise you need the join to find a row for the row to be referred to in theWHEREclause:Also note the use of brackets around the
or, which are needed in SQL because “or” takes precedence over “and” and without brackets you end up with “(A and B) or C”