select
e.E_ID as Employee_ID,
e.E_NAME as Employee_Name,
convert(varchar(10),a.Date,103) as Date ,
convert(varchar(8),a.Timein,108) as Time_In,
convert(varchar(8),a.Timeout,108) as Time_Out
from Employee e
LEFT JOIN Attendance a
ON a.E_ID = e.E_ID
AND (convert(varchar(10),a.Date,103) between '01/02/2013' And '28/02/2013')
上面是我的查询,我从两个表中获取数据,但是它也打印了1月份的值,而不是查询。
我已经调试了一个小时,请任何人帮忙。
答案 0 :(得分:2)
BETWEEN
和dd/mm/yyyy
格式化的字符串无法正常运行!
要在二月份使用
返回行 LEFT JOIN Attendance a
ON a.E_ID = e.E_ID AND a.Date BETWEEN '20130201' AND '20130228'
或者a.Date
中的值可能包含00:00:00
LEFT JOIN Attendance a
ON a.E_ID = e.E_ID AND a.Date >= '20130201' AND a.Date < '20130301'
将列投射到varchar
是不可分割的,这意味着无法使用索引查找,
答案 1 :(得分:1)
Try below and see if it helps
select
e.E_ID as Employee_ID,
e.E_NAME as Employee_Name,
convert(varchar(10),a.Date,103) as Date ,
convert(varchar(8),a.Timein,108) as Time_In,
convert(varchar(8),a.Timeout,108) as Time_Out
from Employee e
LEFT JOIN Attendance a
ON a.E_ID = e.E_ID
Where (convert(varchar(10),a.Date,103) between '01/02/2013' And '28/02/2013')