Home Can I pass DATEADD straight into a variable?
Reply: 2

Can I pass DATEADD straight into a variable?

Eli Rushbrook
Eli Rushbrook Published in 2017-12-06 12:23:32Z

In one of the tSQLt tests I am writing I call a method with parameters to fill the expected table like so:

EXEC Test.Insert_Expected
    @CommencementDt = DATEADD(MONTH, 1, GETDATE)

However I am getting an error over the MONTH part of the second line reading:

'Incorrect syntax near MONTH, expecting ( or SELECT'

I'm new to using parameterised methods and was wandering why this wasn't working, and how I might solve it? Thanks

Jayasurya Satheesh
Jayasurya Satheesh Reply to 2017-12-06 12:34:41Z

try this instead

DECLARE @CommencementDt datetime = DATEADD(MONTH, 1, GETDATE())
EXEC Test.Insert_Expected @CommencementDt

because you can't directly pass the result of a function into the input of a stored procedure. instead, you have to assign the result of the function to a variable and pass that variable to the sp

Yogesh Sharma
Yogesh Sharma Reply to 2017-12-06 12:28:05Z

Try using GETDATE() instead of GETDATE

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304604 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO