This was originally a question about how to implement this, because I was stuck in a certain part, but now I am curious why this happens in the first place. I only needed to compare the dates, not the time, which would not be a problem if the times were not different. The code below shows the request from which I initially tried to execute
SELECT * FROM Employee e inner join OT_Hours o on o.Emp_ID=e.Emp_ID inner join Position p on p.Position_ID=e.Position_ID inner join Signup_Sheet s on s.Employee_ID=e.Emp_ID WHERE e.Eligible_OT=1 and s.Day_Shift = 1 and p.Position_Name = 'Controller' and Convert(Varchar(20),s.Date,101) = '07/26/2010' and Convert(Varchar(20),o.Date,101) <='07/26/2010' and Convert(Varchar(20),o.Date,101) > '07/26/2009' and o.Quantity NOT IN(0.3) order by o.Date DESC
I did not get the result when I ran this query, but when I deleted the second last row, it will return 12 results (<=), and when I delete the third last row, but saved the second, it will return 6 results (>). After reviewing the data, I could see that 4 of these results should have been returned. Now about the alien part. Below is the code I'm currently using.
SELECT DISTINCT o.Date, e.Emp_ID as Emp_ID, e.First_Name+ ' ' +e.Last_Name as Name, o.Quantity as Sum FROM Employee e left join OT_Hours o on o.Emp_ID=e.Emp_ID left join Position p on p.Position_ID=e.Position_ID left join Signup_Sheet s on s.Employee_ID=e.Emp_ID WHERE e.Eligible_OT=1 and s.Day_Shift = 1 and p.Position_Name = 'Controller' and Convert(Varchar(20),s.Date,101) = '07/26/2010' and o.Date between '07/26/2009' and '07/26/2010' and o.Quantity NOT IN(0.3) order by o.Date DESC
This query will return the results, but I also checked it, as I did another, when o.Date was above and below the specified date. When the date was <= 16, the results were returned when 8 results were returned. The final query returned 6 results. Now this is not the production database that I am accessing, and I use it only so that the data does not change. Any explanation of why this is happening? I suppose this has something to do with converting it to varchar, and it can't compare correctly, but that doesn't explain why I would get 12 <=, 6>, and then no results at the end. Also, if anyone knows a better way to implement this, please let me know.