Home All Groups Group Topic Archive Search About

getdate() as a parameter to a stored procedure

Author
8 Jul 2005 4:18 PM
Ken
Assume aStoredProcedure accepts one parameter, a datetime. I would like to do
this:

exec sStoredProcedure @parameter1 = getdate()

....to call it with the current date time, but this results in a syntax
error. Is there any way I can do the above in one statement (i.e. without
declaring and assigning a variable first)?

Author
8 Jul 2005 4:31 PM
Aaron Bertrand [SQL Server MVP]
You can't use a function as a parameter value.  You can declare the
variable, or you can change the stored procedure so that if you leave the
parameter out (or hardcode some token value like 1900-01-01), it populates
the value inline with the value of GETDATE().





Show quote
"Ken" <K**@discussions.microsoft.com> wrote in message
news:A88FD2A1-1F89-4ECA-AA64-3BF23462CDCB@microsoft.com...
> Assume aStoredProcedure accepts one parameter, a datetime. I would like to
> do
> this:
>
> exec sStoredProcedure @parameter1 = getdate()
>
> ...to call it with the current date time, but this results in a syntax
> error. Is there any way I can do the above in one statement (i.e. without
> declaring and assigning a variable first)?
Author
8 Jul 2005 5:32 PM
Cowboy (Gregory A. Beamer) - MVP
DECLARE @Variable DateTime
SET @Variable = GetDate()

exec sStoredProcedure @parameter1 = @Variable

You cannot use a function as a parameter value.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************


Show quote
"Ken" wrote:

> Assume aStoredProcedure accepts one parameter, a datetime. I would like to do
> this:
>
> exec sStoredProcedure @parameter1 = getdate()
>
> ...to call it with the current date time, but this results in a syntax
> error. Is there any way I can do the above in one statement (i.e. without
> declaring and assigning a variable first)?

AddThis Social Bookmark Button