title: A return value cannot be used in this context
body: <p>I have written a function that returns 1 if the date difference is already greater than or equal to 30.</p>
  
  <p>Here is my code:</p>
  
  <pre><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
  </code></pre>
  
  <p>but it has generated this error:</p>
  
  <blockquote>
    <p>Msg 178, Level 15, State 1, Line 16<br>
    A RETURN statement with a return value cannot be used in this context.</p>
  </blockquote>
  
  <p>What does this mean?</p>
  
  <pre><code>CREATE FUNCTION [dbo].[udf_isBonus]
  (@m_id AS INT)
  RETURNS INT
  AS
  BEGIN
      -- Declare the return variable here
      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
  </code></pre>
  
  <p>This is the whole code for this function.</p>