Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Loop through month and year till date while using a merge statement

$
0
0

Hello Guys,

I have 2 tables with the following datas in them:-

Company

CompanyId CompanyName

1                 Company1

2                 Company2

3                 Company3

Employees

EmployeeId EmployeeName CompanyId StartDate

1                  Employee1        1                 12/21/2011

2                  Employee2        1                 01/20/2012

3                  Employee3        2                 03/23/2012

4                  Employee4        2                 07/15/2012

5                  Employee5        2                 01/20/2013

6                  Employee6        3                 12/17/2013

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:-

RecruiterIndicator

CompanyId Year Month EmployeeRecruited

1                 2011 12      1

1                 2012 1        1

2                 2012 3        1

2                 2012 7        1

2                 2013 1        1

3                 2013 12      1

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?

Please help me with this

Thanks

Abhishek


Viewing all articles
Browse latest Browse all 23857

Trending Articles