I wrote a function that returns 1 if the date difference is already greater than or equal to 30.
Here is my code:
DECLARE @flag int
DECLARE @isactive bit
DECLARE @date Datetime
SET @flag = 0
SELECT @isactive = [m_isactive]
FROM dbo.rms_month_email
WHERE m_id = 3
SELECT @date = [m_createddate]
FROM dbo.rms_month_email
WHERE m_id = 3
IF (@isactive = 1 AND DATEDIFF(dd,@date,GETDATE()) = 30)
SET @flag = 1
RETURN @flag
but he generated this error:
Msg 178, Level 15, State 1, Line 16
In this context, you cannot use the RETURN operator with a return value.
What does it mean?
CREATE FUNCTION [dbo].[udf_isBonus]
(@m_id AS INT)
RETURNS INT
AS
BEGIN
DECLARE @flag AS int
DECLARE @isactive AS bit
DECLARE @date AS Datetime
SET @flag = 0
SELECT @isactive = [m_isactive] FROM dbo.rms_month_email WHERE m_id = @m_id
SELECT @date = [m_createddate] FROM dbo.rms_month_email WHERE m_id = @m_id
IF (@isactive = 1 AND DATEDIFF(dd,@date,GETDATE()) = 30)
SET @flag = 1
RETURN @flag
END
GO
This is all the code for this function.
source
share