title: Validate Data in SQL Server Table
body: <p>I am trying to validate the data present in SQL Server table using a stored procedure.
  In one of the validation rules, i have to check whether the value of a particular column is present in another table.</p>
  
  <p>Suppose i have a staging table with following columns Cat_ID, Amount, SRC_CDE</p>
  
  <p>I have a 'maintable' with following columns CatID , Cat_Name</p>
  
  <p>I have to validate whether the Cat_ID present in staging table exists in the 'maintable' for each row</p>
  
  <p>I am using the following statement to validate</p>
  
  <pre><code>if((Select count(*) from maintable where CatID= @Cat_id) &gt;0 )
  -- Do something if data present
  </code></pre>
  
  <p>I want to know if there is any better way of doing the above thing other than using a select query for every row.</p>
  
  <p>Can i use some sort of an array where i can fetch all the CatID from maintable and the check instead of using a select query.</p>
  
  <p>Thanks </p>