Tuesday, October 24, 2017

Monthly, Weekly and Daily Report Query

If you want to report that contain filter of daily,weekly,monthly,yearly you can use this query.What you have to do pass a paramter which report you want for
demo purpose I declare in SQL

DECLARE @Period AS VARCHAR(250)
SET @Period = 'Weekly'
select * from table_name WHERE  entry_datetime >= (CASE
       WHEN @Period = 'Daily' THEN Dateadd(day, -1, Getdate())
       WHEN @Period = 'Weekly' THEN Dateadd(week, -1, Getdate())
       WHEN @Period = 'Monthly' THEN Dateadd(month, -1, Getdate())
       WHEN @Period = 'Yearly' THEN Dateadd(year, -1, Getdate())
       END )
 
 
So this query get all the data that exist in this week

Ref:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/3d380800-dace-4960-9e4d-5766e3a8fe2f/monthly-weekly-and-daily-reports-question?forum=sqlreportingservices

No comments:

Post a Comment