Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

How to get records of last working day using sql server

$
0
0

I need to query an SQL database to get all purchased products on last working date. For example, on Monday I need to get the records of Saturday. Also suppose due to some reason Tuesday is my leave I need to get the records of Monday. I tried my query like:

select ProductName , count(ProductName) as [No Of Products],SUM(Total) as [TotalCost]
from dbo.TransactionDetails
where CurrentTime >=dateadd(day,datediff(day,1,GETDATE()),0)
    AND CurrentTime <dateadd(day,datediff(day,0,GETDATE()),0)
    and  Transaction='BUY'
group by ProductName

But here I am only getting the details of last date.

Also I tried by checking on my last closed shifts:

select ProductName , count(ProductName) as [No Of Products],SUM(Total) as [TotalCost]
from dbo.TransactionDetails
where CurrentTime = (select MAX(Cast(CurrentDateTime as DATE))
from CloseShifts) and Transaction='BUY' group by ProductName

But still I am not getting any result.



M.Sabyasachi



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>