我想查看发票日期只有本周(周一至周日)的记录。当我为接下来的几周运行查询时,我想要设置一个限制,我只能看到那一周的记录。提前感谢您的帮助。
Select ' Amount ' =InvoiceAmount, ' date ' =InvoiceDate from Invoice where InvoiceDate>=.....
DECLARE @Firstdayofcurrentweek DATETIME, @Lastdayofcurrentweek DATETIME
-- First Day of Current Week
SELECT @Firstdayofcurrentweek = DATEADD(wk, DATEDIFF(wk, 0, GETDATE()), 0)
-- Last Day of Current Week
SELECT @Lastdayofcurrentweek = DATEADD(wk, DATEDIFF(wk, 0, GETDATE()), 6)
您的查询:
SELECT [Amount] = InvoiceAmount,
[date] = InvoiceDate
FROM Invoice
WHERE InvoiceDate BETWEEN @Firstdayofcurrentweek AND @Lastdayofcurrentweek