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

Joe Frisbie 21 Reputation points

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,107 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,850 questions
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,582 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114K Reputation points
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Joe Frisbie 21 Reputation points

    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