Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MSSQL – DATEADD value in parameters is returning an error

I’ve built a procedure I need to run it for the last 60 days. I can’t seem to figure it out.

I’ve got the following date parameters statements for the parameters and they return

select dateadd(Day, -60, getdate()), dateadd(Day, -1, getdate())

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

The code itself adjusts the end date to be at the very end of the day. 23:59:59.

When I do this

exec LRP_PROC 
@start_Dt = dateadd(Day, -60, getdate()),
@end_dt = dateadd(Day, -1, getdate()),
@mode = 0

I get the following error

enter image description here

I can’t figure out what i’m doing wrong.
Thank you.

>Solution :

SQL Server does not permit arbitrary expressions to be passed as stored procedure parameters. You need to declare and assign local variables before calling the proc.

eg

declare @start_Dt datetime = dateadd(Day, -60, getdate());
declare @end_dt datetime = dateadd(Day, -1, getdate());

exec LRP_PROC @start_Dt, @end_dt, @mode = 0;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading