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.
| Author |
Topic |
|
coho
Starting Member
3 Posts |
Posted - 2002-01-18 : 16:26:52
|
| I have this User-Defined-Function...CREATE FUNCTION udf (@pCurDate datetime) RETURNS table AS RETURN( -- Trivial details here...)Why would it work as UDF('01/18/02') but not UDF(getdate())from SQL Query Analyzer?Is there any work around?Thanks. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-01-18 : 17:14:33
|
| I remember reading that there were limitations to using certain functions within a UDF, maybe these extend to passing functions as well (though I don't see why). Check Books Online in detail regarding UDFs.As a workaround, simply set a variable equal to getdate() and pass it instead:DECLARE @datevar datetimeSELECT @datevar=getdate()SELECT UDF(@datevar) |
 |
|
|
DGMelkin
Starting Member
24 Posts |
Posted - 2002-01-18 : 18:04:09
|
| I think it has to do with the fact that getdate() has a dynamic value; i.e. you always get a different value everytime you select it. I know that you can't use getdate() within the user defined functions because of that reason. (I already looked into that.)I've also noticed that you can't give stored proc parameters getdate() either, so I think it's related to more than just the function. |
 |
|
|
|
|
|