You are on page 1of 6

select

employee_code,rpt_name,dept_name,birth_date,join_date,DateAdd(Month,6,Dateadd(YEAR,
25,join_date)) as nsif_year,
dbo.GetAge(join_date,'2017-09-30') from per_employee left join lkp_department on
per_employee.company_id=lkp_department.company_id and
per_employee.div_id=lkp_department.div_id
and per_employee.dept_id=lkp_department.dept_id where per_employee.company_id=1
and emp_status<>'S' and category_id=1 order by nsif_year

***************************************************************

SELECT Employee_code,Emp_Name,ISNULL(sum([1990]),0)
as[1990],ISNULL(sum([1991]),0)as [1991], ISNULL(sum([1992]),0) as
[1992],ISNULL(sum([1993]),0) as [1993],
ISNULL(sum([1994]),0) as [1994],ISNULL(sum([1995]),0) as
[1996],ISNULL(sum([1996]),0) as [1996] ,ISNULL(sum([1997]),0) as
[1997],ISNULL(sum([1998]),0) as [1998],
ISNULL(sum([1999]),0) as [1999],ISNULL(SUM([2000]),0) as
[2000],ISNULL(sum([2001]),0) as [2001],ISNULL(sum([2002]),0) as [2002],
ISNULL(sum([2003]),0) as [2003],ISNULL(sum([2004]),0) as
[2004],ISNULL(sum([2005]),0) as [2005],ISNULL(sum([2006]),0) as
[2006],ISNULL(sum([2007]),0) as [2007],
ISNULL(sum([2008]),0) as [2008],ISNULL(sum([2009]),0) as [2009]
FROM [dbo].nsif_det_temp
PIVOT
(
SUM(Year_Contribution)
FOR [nsif_year] IN ([1990],[1991], [1992],[1993], [1994],[1995],[1996],
[1997],[1998],[1999],[2000],[2001],[2002],[2003],[2004],[2005],[2006],[2007],
[2008],[2009])
) AS P group by Employee_code,Emp_Name

***********************************************************
FOR YEAR 2009 November and December
*****************************************************
select employee_id,sum(paycomp_employer1) from pay_calc_detail_history where
employee_id in(select employee_id from per_employee where
company_id=1 and emp_status<>'S' and category_id=1) and pay_comp_id=45 and
pay_year=2009 and pay_month in(11,12)
group by employee_id order by convert(int,employee_id)
**********************************************************

***********************************************************
FROM YEAR 2010 TO 2017
*******************************************************************
SELECT [employee_id],[2010], [2011],[2012], [2013],[2014],[2015],[2016],[2017]
from
(
select [employee_id],[pay_year],[paycomp_employer1]

--ISNULL(sum([2010]),0) as [2010], ISNULL(sum([2011]),0) as


[2011],ISNULL(sum([2012]),0) as [2012],
--ISNULL(sum([2013]),0) as [2013],ISNULL(sum([2014]),0) as
[2014],ISNULL(sum([2015]),0) as [2015] ,ISNULL(sum([2016]),0) as
[2016],ISNULL(sum([2017]),0) as [2017]
FROM [dbo].pay_calc_detail_history where pay_comp_id=45 and pay_year=2009 and
pay_month in(10,11,12)) src
PIVOT
(
SUM([paycomp_employer1])
FOR [pay_year] IN ([2010], [2011],[2012], [2013],[2014],[2015],[2016],
[2017])
) AS P group by [employee_id],[2010], [2011],[2012], [2013],[2014],[2015],[2016],
[2017]

***********************************************************************************
*******

SELECT employee_code,[joinDate],[2010], [2011],[2012], [2013],[2014],[2015],[2016],


[2017] from
(
select [employee_code],dbo.GetAge(join_date,'2017-09-30') as [joinDate],[pay_year],
[paycomp_employer1]

--ISNULL(sum([2010]),0) as [2010], ISNULL(sum([2011]),0) as


[2011],ISNULL(sum([2012]),0) as [2012],
--ISNULL(sum([2013]),0) as [2013],ISNULL(sum([2014]),0) as
[2014],ISNULL(sum([2015]),0) as [2015] ,ISNULL(sum([2016]),0) as
[2016],ISNULL(sum([2017]),0) as [2017]
FROM [dbo].pay_calc_detail_history inner join per_employee On
pay_calc_detail_history.employee_id=per_employee.employee_id
where pay_comp_id=45 and pay_year IN(2010,2011,2012,2013,2014,2015,2016,2017) and
company_id=1 and emp_status<>'S') src

PIVOT
(
SUM([paycomp_employer1])
FOR [pay_year] IN ([2010], [2011],[2012], [2013],[2014],[2015],[2016],
[2017])
) AS P group by [employee_code],[joinDate],[2009],[2010], [2011],[2012], [2013],
[2014],[2015],[2016],[2017]

order by convert(int,[employee_code])

****************************************************************************
--select * from EmployeeMaster
--select * from nsifmaster

With employeemaster as
(
Select
E.empid,
E.empname,
N.nsifyear,
N.nsifamount
From
Dbo.employeemaster E
Inner join dbo.nsifmaster N
On E.empid=N.empid
)
Select * from employeemaster
PIVOT
(max(nsifamount)
for nsifyear in ([2008],[2009],[2010])) p;
************************************************************************
SET RECORDS ZERO ABOVE 25YRS AND 6MONTHS -
**********************************************

DECLARE @EmployeeID INT,@years int


DECLARE @Cursor CURSOR
SET @Cursor = CURSOR FOR
SELECT EmployeeID
FROM NSIF_Final_Report
OPEN @Cursor
FETCH NEXT
FROM @Cursor INTO @EmployeeID

WHILE @@FETCH_STATUS = 0
BEGIN

select @years=Years from NSIF_Final_Report where EmployeeID=@EmployeeID

if @years=2001
begin

UPDATE nsif_test_data SET Y2002=0,


Y2003=0,Y2004=0,Y2005=0,Y2006=0,Y2007=0,Y2008=0,Y2009old=0,y2009new=0,Y2010=0,
Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end

if @years=2002
begin

UPDATE nsif_test_data SET


Y2003=0,Y2004=0,Y2005=0,Y2006=0,Y2007=0,Y2008=0,Y2009old=0,y2009new=0,Y2010=0,
Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end
if @years=2003
begin

UPDATE nsif_test_data SET


Y2004=0,Y2005=0,Y2006=0,Y2007=0,Y2008=0,Y2009old=0,y2009new=0,Y2010=0,
Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end
if @years=2004
begin

UPDATE nsif_test_data SET


Y2005=0,Y2006=0,Y2007=0,Y2008=0,Y2009old=0,y2009new=0,Y2010=0,
Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end
if @years=2005
begin

UPDATE nsif_test_data SET


Y2006=0,Y2007=0,Y2008=0,Y2009old=0,y2009new=0,Y2010=0,
Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end
if @years=2006
begin

UPDATE nsif_test_data SET Y2007=0,Y2008=0,Y2009old=0,y2009new=0,Y2010=0,


Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end
if @years=2007
begin

UPDATE nsif_test_data SET Y2008=0,Y2009old=0,y2009new=0,Y2010=0,


Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end
if @years=2008
begin

UPDATE nsif_test_data SET Y2009old=0,y2009new=0,Y2010=0,


Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end
if @years=2009
begin

UPDATE nsif_test_data SET


Y2010=0,Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end
if @years=2010
begin

UPDATE nsif_test_data SET


Y2011=0,Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE
EmployeeID=@EmployeeID

end
if @years=2011
begin

UPDATE nsif_test_data SET Y2012=0,Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0


WHERE EmployeeID=@EmployeeID

end
if @years=2012
begin

UPDATE nsif_test_data SET Y2013=0,Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE


EmployeeID=@EmployeeID

end
if @years=2013
begin

UPDATE nsif_test_data SET Y2014=0,Y2015=0,Y2016=0,Y2017=0 WHERE


EmployeeID=@EmployeeID

end
if @years=2014
begin

UPDATE nsif_test_data SET Y2015=0,Y2016=0,Y2017=0 WHERE


EmployeeID=@EmployeeID

end
if @years=2015
begin

UPDATE nsif_test_data SET Y2016=0,Y2017=0 WHERE EmployeeID=@EmployeeID

end
if @years=2016
begin

UPDATE nsif_test_data SET Y2017=0 WHERE EmployeeID=@EmployeeID

end

FETCH NEXT
FROM @Cursor INTO @EmployeeID
END

CLOSE @Cursor
DEALLOCATE @Cursor

***********************************************************************************
***************************
update NSIF RATE
***********************************************************************************
*
--select * from lkp_NSIF_Gratuity
--SELECT totalyears, totalmonths,MOnthsEntitled,* FROM nsif_test_data a order by
a.totalyears desc

DECLARE @EmployeeID INT,@years int,@months int,@NSIFRate numeric(16,3)


DECLARE @Cursor CURSOR

SET @Cursor = CURSOR FOR


SELECT EmpID FROM nsif_test_data
OPEN @Cursor
FETCH NEXT
FROM @Cursor INTO @EmployeeID

WHILE @@FETCH_STATUS = 0
BEGIN

select @years=TotalYears,@months=TotalMonths from nsif_test_data where


EmpID=@EmployeeID
print'TotalYears'
print @years
print 'Total months'
print @months

select @NSIFRate=gratuity_rate from lkp_NSIF_Gratuity where year=@years and


month=@months

print '@NSIFRate'
print @NSIFRate

IF NOT EXISTS(SELECT gratuity_rate from lkp_NSIF_Gratuity where year=@years and


month=@months)
BEGIN
UPDATE nsif_test_data SET MonthsEntitled=36 where EmpID=@EmployeeID
END

ELSE

BEGIN
UPDATE nsif_test_data SET MonthsEntitled=@NSIFRate where EmpID=@EmployeeID
END

FETCH NEXT
FROM @Cursor INTO @EmployeeID
END

CLOSE @Cursor
DEALLOCATE @Cursor
***************************************************************

update nsif_test_data SET TotalMonths=dbo.GetMonth(join_date,'2017-09-30') from


per_employee where
empid=employee_id
update nsif_test_data SET TotalYears=dbo.GetYear(join_date,'2017-09-30') from
per_employee where
empid=employee_id

SELECT * FROM nsif_test_data a order by TotalYears desc

update nsif_test_data set


Total1=(Y1990+Y1991+Y1992+Y1993+Y1994+Y1995+Y1996+Y1997+Y1998+Y1999+y2000+Y2001+Y20
02+Y2003+y2004+Y2005+Y2006+Y2007+y2008+Y2009old)/100

update nsif_test_data set


Total2=Y2009New+Y2010+y2011+y2012+y2013+y2014+y2015+y2016+Y2017

update nsif_test_data set TotalContribution=(Total1+Total2)

update nsif_test_data set Gratuity=MonthsEntitled * TotalCoreCola

update nsif_test_data set DiffrenceInGratuity=Gratuity-TotalContribution

********************************************************************************

You might also like