title: Sql Function Issue "The last statement included within a function must be a return statement"
body: <p>In the below SQL function I have to return value based on condition but it throws a error.</p>
  
  <blockquote>
    <p>"The last statement included within a function must be a return
    statement."</p>
  </blockquote>
  
  <p>Pls help me to overcome this issue.</p>
  
  <pre><code>ALTER FUNCTION [dbo].[GetBatchReleaseQuantity]   
  (
  @i_LocationID VARCHAR(50),
      @i_ProductID INT,
      @i_StartDate VARCHAR(50),  
      @i_EndDate VARCHAR(50),  
      @i_ProductInFlow int
  )  
  RETURNS numeric(18,3)  
   --WITH ENCRYPTION     
  AS  
  BEGIN  
  
    IF (@i_ProductInFlow ='2')
    BEGIN
  
    RETURN (SElECT ISNULL( SUM( BatchReleaseQuantity),0.00)  From  BatchReleaseDetails BRD
    LEFT OUTER JOIN BatchRelease BR ON BR.BatchReleaseID=BRD.BatchReleaseID
    Where  ProductId=@i_ProductID  AND LocationID=@i_LocationID AND BRD.CreatedOn&gt;=convert(datetime,@i_StartDate+' 00:00:00') AND BRD.CreatedOn&lt;=convert(datetime,@i_EndDate+' 23:59:59'))
    END
    ELSE
    BEGIN
    RETURN(SElECT ISNULL( SUM( AcceptedQuantity),0.00)  From  GoodsReceivedNoteDetail GRND
    LEFT OUTER JOIN GoodsReceivedNote GRN ON GRN.LocationID=@i_LocationID
    Where  ProductId=@i_ProductID  AND GRN.LocationID=@i_LocationID AND GRND.CreatedOn&gt;=convert(datetime,@i_StartDate+' 00:00:00') AND GRND.CreatedOn&lt;=convert(datetime,@i_EndDate+' 23:59:59'))
    END 
  END
  </code></pre>