我datediff
在查询中使用返回距开始日期不到 7 天的日期。
DECLARE @d1 DATE
SET @d1 = (SELECT CurrentServiceWeek FROM Technician WHERE ID = 150)
SELECT
First_Name, Last_Name, Previous_Service_Date,
Address1, Address2, City, [State], Zip
FROM
Customer
JOIN
CustomerAddress ON Customer.ID = Customer_ID
WHERE
Technician_ID = 150
AND DATEDIFF(day, (@d1), (SELECT Previous_Service_Date
FROM Customer
WHERE Technician_ID = 150)) < 7
这datediff
也给了我不止一个结果。CurrentServiceWeek
等于 3/11/2016 并且是开始日期,因此任何 6 天后的日期都足以查询。但它作为Previous_Service_Date
值返回的日期是:
4/5/2015
3/6/2016
所以查询应该只返回 2016 年 3 月 6 日的日期。有人可以帮我看看我哪里出错了吗?自从我为参数传递了一天以来,是否DATEDIFF
忽略了日期中的年份datepart
?