title: How to get Return Value of a Stored Procedure
body: <p>Probably an easy-to-answer question. I have this procedure:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[AccountExists]
      @UserName nvarchar(16)
  AS
  IF EXISTS (SELECT Id FROM Account WHERE UserName=@UserName)
  SELECT 1
  ELSE SELECT 0 
  </code></pre>
  
  <p>When I have ADO.NET code that calls this procedure and does this:</p>
  
  <pre><code>return Convert.ToBoolean(sproc.ExecuteScalar());
  </code></pre>
  
  <p>Either true or false is returned.</p>
  
  <p>When I change the stored procedure to RETURN 1 or 0 instead of SELECT:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[AccountExists]
      @UserName nvarchar(16)
  AS
  IF EXISTS (SELECT Id FROM Account WHERE UserName=@UserName)
  RETURN 1
  ELSE RETURN 0 
  </code></pre>
  
  <p>sproc.ExecuteScalar() returns null. If I try sproc.ExecuteNonQuery() instead, -1 is returned.</p>
  
  <p><strong>How do I get the result of a stored procedure with a RETURN in ADO.NET?</strong></p>
  
  <p>I need AccountExists to RETURN instead of SELECT so I can have another stored procedure call it:</p>
  
  <pre><code>--another procedure to insert or update account
  
  DECLARE @exists bit
  
  EXEC @exists = [dbo].[AccountExists] @UserName 
  
  IF @exists=1
  --update account
  ELSE
   --insert acocunt
  </code></pre>