title: Loop through month and year till date while using a merge statement
body: <p>I have 2 tables with the following datas in them:-</p>
  
  <p>Company</p>
  
  <p>CompanyId CompanyName</p>
  
  <p>1         Company1</p>
  
  <p>2         Company2</p>
  
  <p>3         Company3</p>
  
  <p>Employees</p>
  
  <p>EmployeeId EmployeeName CompanyId StartDate</p>
  
  <p>1          Employee1        1     12/21/2011</p>
  
  <p>2          Employee2        1     01/20/2012</p>
  
  <p>3          Employee3        2     03/23/2012</p>
  
  <p>4          Employee4        2     07/15/2012</p>
  
  <p>5          Employee5        2     01/20/2013</p>
  
  <p>6          Employee6        3     12/17/2013</p>
  
  <p>Now i want to check, How many people were recruited in the team in the specified month and year? I have the storage table as follows:-</p>
  
  <p>RecruiterIndicator</p>
  
  <p>CompanyId Year Month EmployeeRecruited</p>
  
  <p>1         2011 12      1</p>
  
  <p>1         2012 1        1</p>
  
  <p>2         2012 3        1</p>
  
  <p>2         2012 7        1</p>
  
  <p>2         2013 1        1</p>
  
  <p>3         2013 12      1</p>
  
  <p>This should be a merge stored procedure that should update the data if it is present for the same month year and company and insert if that is not present? The loop would start from a particular date that can be an parameter and it would loop through the current month.</p>
  
  <p>Please help me with this</p>
  
  <p>Thanks</p>
  
  <p>Vishal</p>