sparkyrose
Programmer
Hi All,
I'm trying to create a UDF (SQL Server 2000, btw) which will take the date from a column in the same table, add years based on a calculation of two other columns, and arrive at the final date.
If it's helpful to know I'm taking the end of a current lease, adding the renewal options, and arriving at the final lease end date. I need the If...Else part because not all leases have available renewals
This is what I came up with but it gives two error messages, listed below the code.
Server: Msg 444, Level 16, State 2, Procedure LeaseEndFunc, Line 10
Select statements included within a function cannot return data to a client.
Server: Msg 455, Level 16, State 1, Procedure LeaseEndFunc, Line 65535
The last statement included within a function must be a return statement.
Any pointers gratefully appreciated!
I'm trying to create a UDF (SQL Server 2000, btw) which will take the date from a column in the same table, add years based on a calculation of two other columns, and arrive at the final date.
If it's helpful to know I'm taking the end of a current lease, adding the renewal options, and arriving at the final lease end date. I need the If...Else part because not all leases have available renewals
This is what I came up with but it gives two error messages, listed below the code.
Code:
CREATE FUNCTION LeaseEndFunc
(@Currenttermend DateTime,
@RenewalPeriods Decimal (9),
@RenewPeriodLen Decimal (9))
RETURNS DateTime
AS
BEGIN
IF (SELECT RenewalPeriods FROM dbo.[Main Table]) Is Null
BEGIN
(SELECT Currenttermend FROM dbo[Main Table])
END
ELSE
RETURN (SELECT dateadd(year,([RenewalPeriods] * [RenewPeriodLen]),[Currenttermend])
FROM dbo.[Main Table])
END
Server: Msg 444, Level 16, State 2, Procedure LeaseEndFunc, Line 10
Select statements included within a function cannot return data to a client.
Server: Msg 455, Level 16, State 1, Procedure LeaseEndFunc, Line 65535
The last statement included within a function must be a return statement.
Any pointers gratefully appreciated!