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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Optional Parameters

Author  Topic 

label
Posting Yak Master

197 Posts

Posted - 2003-11-06 : 12:30:40
I've seen stored procedures in the past use optional paramters. I'm trying to do the same thing here:


CREATE PROCEDURE dbo.ap_get_leads_by_branch

@branch varchar(50),
@from_Date datetime = dateadd(yy, -1, getdate()),
@to_date datetime = getdate()

AS
.
.
.


however I'm getting an error. What am I doing wrong here?

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-06 : 12:32:43
Well, what's your error?

But here is an example:

CREATE PROCEDURE [dbo].usp_GetEquipmentGroupDetails
(
@userID int = 1
,@CompanyID int = 11958
,@lang varchar(20) = 'english'
,@isAdmin int = 1
,@userTimeZone varchar(20) = 'PST'
,@AssetGroupID int
)
AS
...

Tara
Go to Top of Page

label
Posting Yak Master

197 Posts

Posted - 2003-11-06 : 12:45:57
quote:
Originally posted by tduggan
Well, what's your error?



Sorry, spaced posting that.

The error is:

"Error 170: Line 4: Incorrect syntax near '('."

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-06 : 12:48:50
You probably can't use GETDATE() or any functions for the defaults of your variables. You could just set the defaults to NULL. Then in your code:


IF @from_date = NULL
SET @from_date = dateadd(yy, -1, getdate())
...




Tara
Go to Top of Page

label
Posting Yak Master

197 Posts

Posted - 2003-11-06 : 12:54:31
quote:
Originally posted by tduggan

You probably can't use GETDATE() or any functions for the defaults of your variables.



Yep, that was it. Thanks for your help.
Go to Top of Page
   

- Advertisement -