how to select yesterday data in where condition in sql server code example
Example: comparing with today and yesterday record in sql query
declare @bgn_dt date = '2017-12-15'
, @end_dt date = '2017-12-22'
, @lag_dt date;
set @lag_dt = (select max(MyDate) from
select a.MyDate
, a.SalesTotal
, format(((1.0 * a.SalesTotal) / a.SalesTotalPrevDay) - 1, '0%') as SalesTotalChange
from (
select t.MyDate
, t.SalesTotal
, lag(t.SalesTotal, 1, NULL) over ( order by t.MyDate asc) as SalesTotalPrevDay
from
where 1=1
and t.MyDate between @lag_dt and @end_dt
) as a
where 1=1
and a.MyDate >= @bgn_dt