title: Use if statement and return value to c# from a stored procedure in SQL Server
body: <p>All I want to do is check if a name exists in a given table in my database or not but I am getting multiple returns from the stored procedure causing an exception.</p>
  <p>This is the stored procedure I am using in SQL Server:</p>
  <pre><code>CREATE OR ALTER PROCEDURE ContactExists 
      @Name varchar(50)
  AS
  BEGIN
      SET NOCOUNT ON;
  
      DECLARE @result bit = 0
      DECLARE @name varchar(50) = '';
  
      SET @name = (SELECT Name FROM Table)
  
      IF (@name = @Name)
      BEGIN
          SET @result = 1
          RETURN @result
      END
  
      RETURN @result
  END
  GO
  </code></pre>
  <p>And this is the method I am using in C#:</p>
  <pre><code>SPstr = &quot;dbo.ContactExists&quot;;
  
  SqlCommand cmd = new SqlCommand(SPstr, connection);
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Parameters.AddWithValue(&quot;@Name&quot;, Name);
  
  var returnValue = cmd.Parameters.Add(&quot;@result&quot;, SqlDbType.Int);
  returnValue.Direction = ParameterDirection.ReturnValue;
  
  cmd.ExecuteNonQuery();
  
  return (int)returnValue.Value;
  </code></pre>