sql server - Fetching record of last 48 hrs from SQL -
i have table1 with columns datetime
, id
, status
.
i call stored procedure after specific hours , want fetch records of last 48 non weekend hours.
i tried writing case each day of getdate()
.
i want know best way this.
to avoid weekends, can use case
or other logic in where
. logic isn't 100% clear on over weekend days. here approach:
where (datename(wk, getdate()) in ('sunday', 'monday', 'tuesday') , datetime >= dateadd(hour, 48 + 48, getdate()) ) or (datename, wk, getdate()) in ('wednesday', 'thursday', 'friday') , datetime >= dateadd(hour, 48, getdate()) or (datename , wk, getdate()) in ('saturday') , datetime >= dateadd(hour, 24 + 48, getdate());
Comments
Post a Comment