Created
August 4, 2018 12:21
-
-
Save SergiyOsadchyy/cdb74a7599daa32530164685877e3e84 to your computer and use it in GitHub Desktop.
MS SQL get dates from previous week (DATEADD and DATEDIFF)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT salesDate | |
, customerName | |
, productName | |
, salesQty | |
, salesQty * productPrice as 'Total' | |
FROM testDB.dbo.salesDaily | |
INNER JOIN testDB.dbo.customers ON testDB.dbo.customers.custId = customerId AND customerName = 'Customer2' | |
INNER JOIN testDB.dbo.products ON testDB.dbo.products.prodId = productId | |
WHERE salesDate >= DATEADD(WK, DATEDIFF(WK, 0, GETDATE()) - 1, 0) | |
AND salesDate < DATEADD(WK, DATEDIFF(WK, 0, GETDATE()), 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment