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)
 Function-Using parammeters with default

Author  Topic 

tuenty
Constraint Violating Yak Guru

278 Posts

Posted - 2005-11-22 : 09:06:54
I have this function

Create  FUNCTION dbo.monthlyClaimUtilization (@from as datetime = '1/1/1900', @to as datetime = '1/1/1900', @groupNum nvarchar(6)='%')
RETURNS table


It worked fine until I tried to reset the value of @to when it had the default value

I tried this

Select case @to When  '1/1/1900' then DATEADD(d, - (DATEPART(d,Getdate())), Getdate()) else @to


and this

If @to = '1/1/1900'
Set @to = DATEADD(d, - (DATEPART(d,Getdate())), Getdate())


with and without the word BEGIN before and with the word RETURN after. But I always get one or two errors of the following:
Invalid use of 'getdate' within a function
Incorrect syntax near the keyword 'Select'
Incorrect syntax near 'BEGIN'
Incorrect syntax near ')'




A candle loses nothing by lighting another candle

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2005-11-22 : 09:43:15
Yes. you can't use getdate in a function.

-----------------
[KH]
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-11-22 : 09:58:12
But you can pass it in as a value...
Go to Top of Page

tuenty
Constraint Violating Yak Guru

278 Posts

Posted - 2005-11-22 : 11:23:42
Thank you

I have now an SP passing the parameters


A candle loses nothing by lighting another candle
Go to Top of Page
   

- Advertisement -