bakershawnm
Programmer
Using MS Sql Server 2005 I have the following funcion:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION DeltaDays
(
-- Add the parameters for the function here
@StrtDate datetime,
@EndDate datetime
)
RETURNS int
AS
BEGIN
-- Declare the return variable here
DECLARE @Result int
DECLARE @dayofweek as INT
-- Add the T-SQL statements to compute the return value here
WHILE DATEDIFF(day, @StrtDate, @EndDate) > 0
BEGIN
SET @dayofweek = DATEPART(WEEKDAY, @StrtDate)
IF @dayofweek > 1 AND @dayofweek < 7
BEGIN
SELECT DOWNDAYS_I
FROM KMM.dbo.DD010000
WHERE DOWNDAYS_I = @StrtDate
-- IF DOWNDAYS_I IS NULL
-- BEGIN
-- set @Result = @Result + 1
-- END
END
SET @StrtDate = DATEADD(day, 1, @StrtDate)
END
-- Return the result of the function
RETURN @Result
END
GO
I get the following error:
Msg 444, Level 16, State 2, Procedure DeltaDays, Line 25
Select statements included within a function cannot return data to a client.
From everything I have found this error usually indicates returning more than one record. However with the WHERE clause I should get either 1 of 2 results; either a null or a single date.
If this error is not because of the SELECT statement then what is it on and what do I need to do to fix this?
Thanks