question

JoeFrisbie-5876 avatar image
0 Votes"
JoeFrisbie-5876 asked Jason-MSFT edited

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

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-generalsql-server-transact-sqlsql-server-reporting-services
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
1 Vote"
Viorel-1 answered pituach commented
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Why you added this message as comment and not as answer?

This looks the answer, but the OP cannot mark it.

1 Vote 1 ·

Hi @JoeFrisbie-5876,

Helped convert Viorel-1's comment as answer.

As Viorel-1 said, you may replace -60 with @NumberOfDays.

If this helps on your issue, you could mark it as answer so other user with similar problem could see this easier. :)

Regards,

Zoe


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 Votes 0 ·

Helped convert Zoehui-MSFT's response to comment, as it should be

1 Vote 1 ·
JoeFrisbie-5876 avatar image
0 Votes"
JoeFrisbie-5876 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.