Passing parameters

Hi,

I have a sp that takes two dates as parameters.  When I run it using two dates, exec my-sp '1/29/2018', '1/29/2018', it runs fine. But when I use this

Exec my-sp DATEADD(day, DATEDIFF(day,0,GETDATE())-1,0),DATEADD(day, DATEDIFF(day,0,GETDATE())-1,0)

it shows the error

Incorrect syntax near 'day'.

I am not sure where the problem is. thanks
mcrmgAsked:
Who is Participating?
 
ste5anConnect With a Mentor Senior DeveloperCommented:
See EXECUTE (Transact-SQL):

Parameters must be either values (literals) or variables. Expressions are not allowed.

E.g.

DECLARE @p1 DATE = DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()) - 1, 0);
DECLARE @p2 DATE = DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()) - 1, 0);

EXECUTE my_sp @p1 ,
              @p2;

Open in new window

0
 
mcrmgAuthor Commented:
thank you. I will assign it to a variable first.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.