title: Counting records in SQL Server
body: <p>Take a look at this SP.</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[sp_GetRecTitleVeh] 
  
  AS
  BEGIN
  select 
      a.StockNo, c.ClaimNo,
      v.VIN, v.[Year],v.Make, v.Model,
      c.DOAssign, t.DOLoss, t.RecTitleDate
  From 
      dbo.Assignments a,
      dbo.Assignment_ClaimInfo c,
      dbo.Assignment_TitleInfo t,
      dbo.Assignment_VehicleInfo v
  Where 
      a.AssignmentID= c.AssignmentID and
      c.AssignmentID= t.AssignmentID and
      t.AssignmentID= v.AssignmentID and
      t.RecTitleDate is not null and
      c.InsuranceComp = 'XYZ' and
      a.StockNo not in (select StockNo from dbo.Invoice where InvoiceType = 'Payment Invoice') 
  order by t.RecTitleDate
  END
  </code></pre>
  
  <p>This SP works fine and gives me required result.</p>
  
  <p>What i need is to ask that is there any shortest way to count records obtained by executing this SP. For ex. i am trying like this </p>
  
  <pre><code>select count(*) from sp_GetRecTitleVeh
  </code></pre>
  
  <p>I know that there is a solution like - </p>
  
  <pre><code>ALTER PROCEDURE [dbo].[sp_CountRecTitleVeh] 
  
  AS
  BEGIN
  select 
      count(a.StockNo)
  From 
      dbo.Assignments a,
      dbo.Assignment_ClaimInfo c,
      dbo.Assignment_TitleInfo t,
      dbo.Assignment_VehicleInfo v
  Where 
      a.AssignmentID= c.AssignmentID and
      c.AssignmentID= t.AssignmentID and
      t.AssignmentID= v.AssignmentID and
      t.RecTitleDate is not null and
      c.InsuranceComp = 'XYZ' and
      a.StockNo not in (select StockNo from dbo.Invoice where InvoiceType = 'Payment Invoice') 
  order by t.RecTitleDate
  END
  </code></pre>
  
  <p>Do you have any idea how could i count records got by executing SP.</p>
  
  <p>Thanks for sharing your valuable time.</p>