SQL Query:How to use a variable for number of days in a DATEADD expression.

Joe Frisbie 21 Reputation points
2022-02-03T21:12:05.947+00:00

I am not so good at SQL, however, I am trying to take a DATEADD expression we use in an SCCM SSRS report

"Where GSWS.[LastHWScan] >= DATEADD(DAY, -60, GETDATE()) "

And change the -60 entry to use a variable "@NumberOfDays" we prompt for when running the report.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,361 questions
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.
2,878 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,601 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.7K Reputation points
    2022-02-03T22:07:02.877+00:00
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Joe Frisbie 21 Reputation points
    2022-02-04T16:38:23.503+00:00

    Thank you all, it works. Now I have to understand how to add the variable as a dataset in SSRS to put it all together.

    0 comments No comments