title: How to count the rows of a varchar column and return an integer?
body: <p>I am writing code that needs to recognize if a column is empty or not in my database based on a specific ID. I am using Microsoft SQL Server Management Studio.</p>
  
  <p>I've tried:</p>
  
  <pre><code>select count(*) as valid from table where id =7PB03150SW
  </code></pre>
  
  <p>But receive the error:</p>
  
  <p><em>Conversion failed when converting the varchar value to data type int.</em></p>
  
  <p>I also tried:</p>
  
  <pre><code>select cast(( select count(*) from table where id = 7PB03150SW)as VarChar(120))
  </code></pre>
  
  <p>But receive the error:      </p>
  
  <p><em>Conversion failed when converting the varchar value to data type int.</em></p>
  
  <p>I want the code to output a single result, the number of times the specific ID appears in the table. The output needs to be able to be read by a c# file.</p>