我正试图在当前一周内从我的数据库中获取所有数据..如果那周已经结束,我希望下周的数据显示而不显示最后几周的数据....
这是我的代码:我尝试过使用YearWeek()
Select
systemusers.FirstName,
systemusers.MiddleName,
systemusers.LastName,
temperaturelogs.DateTime,
Locations.Description,
temperaturelogs.UnitID,
temperaturelogs.Temperature,
temperaturelogs.Humidity
From temperaturelogs
Inner Join Locations
On temperaturelogs.LocationID = Locations.LocationID
Inner Join SystemUsers
On temperaturelogs.Encoder = systemusers.UserID
Where
YEARWEEK('3/21/2016') = YEARWEEK(NOW())
AND
temperaturelogs.Encoder = 2 Order By temperaturelogs.DateTime DESC
答案 0 :(得分:0)
基于星期一12:00 AM至星期日11:59:59.999 PM的一周
Where YourColumn >= DATEADD(wk, DATEDIFF(wk, 0, GETDATE() -1), 0)