CREATE PROCEDURE [P_payin]
@year varchar(20),
@year2 varchar(20),
@dept_code varchar(20)
AS
declare @code2 varchar(20)
declare code insensitive cursor for select ext_empid from v_pextendout where ext_date=@year and ext_empid in (select emp_id from v_employee where emp_dept like @dept_code+'%')
open code
fetch next from code into @code2
while @@fetch_status=0
begin
if not exists(select ext_empid from pextend where ext_date=@year2 and ext_empid=@code2 )
begin
insert into pextend select Ext_EmpId, @year2,ext_empcode, Ext_APay, Ext_SPay, Ext_Absent, Ext_Duty, Ext_Admin, Ext_Tech, Ext_Foreign, Ext_Live, Ext_Covertime, Ext_Prink, Ext_Drink, Ext_Temp, Ext_Overtime, Ext_Supper, Ext_Outlength, Ext_Inlength, Ext_Aged, Ext_Medicare,Ext_House, Ext_Dorm, Ext_Tax, Ext_Bail, Ext_Should, Ext_Lateleave, Ext_Add, Ext_Cut,null from v_pextendout where ext_date=@year and ext_empid=@code2 --in (select emp_id from v_employee where emp_dept like '@dept_code%')
end
fetch next from code into @code2
end
CLOSE code
DEALLOCATE code
GO