I was using the exact same query to get data from two tables. when i dont use the c.IsReceived = 0 part, it returns Dates but it doesn’t return anything when it is used. There are rows in RepDailyCollection with IsReceived = 0 for RepID = 205. What do you think i am doing wrong? This is in 2005 SQL Server. thnak you!!
Select
distinct RepDailyInfo.Date
from
RepDailyInfo
left outer join
RepDailyCollection c
on
c.RepDailyCollectionID = RepDailyInfo.RepDailyInfoID
where
RepDailyInfo.RepID = 205 and c.IsReceived = 0
Edit:
When i use an other stored proc similar to this works fine.
Select i.Date
--i.RepDailyInfoID, i.RepID, i.TypeofDayID, i.CommuniTeeID, sum(cast(c.AmountSold as numeric(10,2))) as AmountSold,
-- sum(cast (c.AmountCollected as numeric(10,2))) as AmountCollected, c.NewCompanyName,c.PaymentMethod,
-- c.TypeofCreditCard, c.CheckNumber, c.Invoice, c.Spots, TypeofDay.TypeofDay, CommuniTee.City, CommuniTee.State,
-- CommuniTee.year, SalesRep_Info.FirstName, SalesRep_Info.LastName
from RepDailyInfo i
left outer join RepDailyCollection c on i.RepDailyInfoID = c.RepDailyInfoID
left outer join TypeOfDay on TypeOfDay.TypeofDayID = i.TypeofDayID
left outer join SalesRep_Info on SalesRep_Info.RepID = i.RepID
left outer join CommuniTee on CommuniTee.CommuniTeeID = i.CommuniTeeID
where i.RepID = 205 and c.IsReceived = 0
group by i.RepDailyInfoID, i.Date, i.TypeofDayID, i.CommuniTeeID, SalesRep_Info.FirstName, TypeofDay.TypeofDay,
CommuniTee.City, CommuniTee.State, CommuniTee.year, SalesRep_Info.FirstName,
SalesRep_Info.LastName, i.RepID, c.NewCompanyName, c.PaymentMethod, c.TypeofCreditCard, c.CheckNumber, c.Invoice, c.Spots
order by SalesRep_Info.FirstName desc
There are a number of things wrong here.
In the first query you have:
Even though you say “left outer join”, due to the where clause you may as well have said inner join.
Regardless, this query doesn’t match the second one. In the second query you are joining RepDailyCollection to RepDailyInfo on RepDailyInfoID. In the first query you are joining on completely different columns.