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 |
|
hong_ma
Starting Member
37 Posts |
Posted - 2006-02-22 : 13:56:56
|
| I have a table which has six fields ID, dateDue, dateReceived, dueday. month, ContactFYEmy query looks likeselect ID, DateDue, dateReceived, dueday, month, ContactFYEfrom Reportwhere (dbo.Report.DateDue BETWEEN dbo.udfDisplayTime(dueday, month, ContactFYE) AND DateDue )user defined functionCREATE FUNCTION dbo.udfDisplayTime ( @dueday int, @month int, @ContactFYE smalldatetime) RETURNS smalldatetime AS BEGIN DECLARE @ReturnString AS smalldatetime Declare @dueday1 as int if (@month =1)beginset @dueday1 = @dueday -7endelse if (@month =2)begin set @dueday1 = @dueday -14end else if (@month =3)begin set @dueday1 = @dueday -60endselect @ReturnString = DATEADD ( dd, @dueday1, @ContactFYE) Return @ReturnStringENDI got a incorrect result when using this query and user defined function.the result that I got was out of between displaytime and datdue. any idea for this , Thanks. |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-02-22 : 14:09:36
|
| Hints:1. Execute the function alone with necessary parameters and see whether it returns the date that you expect2. Is DateDue also of smalldatetime ? (I don't know whether that matters but you can check3. Hardcode the "expected results of function" to the query and execute |
 |
|
|
hong_ma
Starting Member
37 Posts |
Posted - 2006-02-22 : 15:25:07
|
| I am not sure if the problem comes from where condition where (dbo.Report.DateDue BETWEEN dbo.udfDisplayTime(dueday, month, ContactFYE) AND DateDue )becasue udfDisplayTime always changed, not a fixed value |
 |
|
|
|
|
|
|
|