Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored Procedure parameter question

Author  Topic 

Aleph_0
Yak Posting Veteran

79 Posts

Posted - 2011-08-01 : 19:01:59
Hi again, just a quick question: I have a stored procedure that takes 2 date parameters (a start date and an end date), and I tried something like this:

EXEC MyTableBuild Dateadd(YEAR, -1, @endDate), @endDate

But I'm getting an error that says:

Msg 102, Level 15, State 1
Incorrect syntax near 'YEAR'.

Is the only solution to declare a new variable for the start date? My goal is to have this stored procedure take just one datetime parameter (@endDate) and be able to execute several other stored procedures that have their own datetime parameters that depend on @endDate in different ways.

Thanks!

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-08-01 : 19:16:20
Try
EXEC (MyTableBuild Dateadd(YEAR, -1, @endDate), @endDate)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Aleph_0
Yak Posting Veteran

79 Posts

Posted - 2011-08-01 : 19:31:42
Still getting the same error, only it says
Incorrect syntax near 'MyTableBuild'

Thanks though.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-08-01 : 19:38:43

EXEC (MyTableBuild ( Dateadd(YEAR, -1, @endDate), @endDate)
)

Jim


Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -