Date parameter in Microsoft Report Builder.

Greg O'Connell 21 Reputation points
2020-09-28T13:40:54.89+00:00

Good Afternoon,

I have written an SQL query that returns specific door access activity on any given date, and then breaks it down in to In and Out per hour of that date.

If I use
WHERE eventtime = '02/02/2020'
I would get no results, so I have to use WHERE eventtime BETWEEN '02/02/2020' AND '02/03/2020'
to get the results I want within that 24 hour period, which is fine, no issue there.

The issue I have is with turning this in to a report in Microsoft Report Builder without having to use two parameters Start date and End Date.
I just want to use the date parameter to select the Start Date and have the report builder automatically turn that in to the 24 hour period that I need to display the specific records.

I hope that makes sense.

Kind Regards

Greg

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,061 questions
Developer technologies Transact-SQL
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 47,436 Reputation points
    2020-09-28T14:10:05.257+00:00

    Hello Greg,

    Is the data source a MS SQL Server? Then you can use the SQL function DATEADD to add a day on the parameter value

    SELECT *  
    FROM yourTable  
    WHERE eventtime BETWEEN '02/02/2020' AND DATEADD(day, 1, '02/02/2020')  
    

2 additional answers

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2020-09-28T21:57:04.583+00:00

    Olaf's answer is not entirely correct. The WHERE clause should be written litke this:

    WHERE eventtime >= '02/02/2020' 
       AND eventtime < DATEADD(day, 1, '02/02/2020')
    

    You should probably not include events that fall exactly on midnight the next date.

    0 comments No comments

  2. San 1 Reputation point
    2022-08-29T19:13:17.257+00:00

    Adding the above syntax at the END of the overall query does not work. WHERE in the query should this be placed? Can someone please provide an example video, or an example with screen shots? Many thanks!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.