title: SQL Server : the last statement included within a function must be a return statement
body: <p>I'm writing the following function to check the row in a table based on the parameter that I pass to function and return a data-type bit result.</p>
  
  <p>Here is the function:</p>
  
  <pre><code>create function dbo.udf_my_func(@var1 varchar(15), @var2 varchar(30))
  returns bit as  
  begin 
      if not exists (select 1 from Sample_table(nolock) where var1 = @var1 and var2 = 1)
      begin
          return 0
      end
  
      if exists (select 1 from Sample_table(nolock) where var1 = @var1 and var2 = @var2)
      begin
          return 1
      end
  
      if exists (select 1 from Sample_table(nolock) where var1 = @var1 and var2 &lt;&gt; @var2)
      begin
          return 0
      end
  
  end
  go
  </code></pre>
  
  <p>But I'm getting this error:</p>
  
  <blockquote>
    <p>The last statement included within a function must be a return statement</p>
  </blockquote>
  
  <p>Please let me know how to fix this one. Thanks in advance!</p>