I have created a stored procedure which takes 3 parameters. See below
ALTER PROCEDURE [dbo].[Leave_Allocation_Mar_2016]
@Type nvarchar(10),
@Month int,
@Year int
AS
BEGIN
declare @emp_card_no numeric(9)
declare @emp_name varchar(20)
declare @dt_of_join datetime
declare @Total_days numeric(5,2)
declare @Days_worked numeric(5,2)
declare @Final_PaidDayLop numeric(5,2)
declare @TotalRecord int
declare @actualMonth int
declare @actualYear int
declare @actuallastdate varchar(20)
IF(@Type = 'C')
BEGIN
Print 'Yes I am in the Current process';
DECLARE daily_Allocate CURSOR FOR
Select distinct c.emp_card_no, c.emp_name, c.Dt_Of_Join from emp_mst c
join emp_mon_day d
on c.emp_card_no=d.emp_mkey
WHERE Dt_Of_Join = CAST(FLOOR(CAST( DATEADD(month, -6, GETDATE()) AS FLOAT ))AS DATETIME)
OPEN daily_Allocate
FETCH NEXT FROM daily_Allocate INTO
@emp_card_no, @emp_name, @Dt_Of_Join
WHILE @@FETCH_STATUS = 0
BEGIN
select @Total_days = Sum(total_day),@Days_worked = Sum(days_worked)
from emp_mon_day a
where a.emp_mkey = 2519
group by emp_mkey
PRINT 'Employee Card no = ' + cast(@emp_card_no as char)
PRINT 'Total days = ' + cast(@Total_days as char)
PRINT 'Days Worked = ' + cast(@Days_worked as char)
set @Final_PaidDayLop = 0;
set @TotalRecord = 0;
Select @Final_PaidDayLop =
isnull(sum(days),0)
from P_Emp_Del_App_Hdr c join P_Emp_Del_App_trl d on c.mkey=d.mkey
where c.delete_flag='N' and app_flag='Y' and c.year = @actualYear
and c.emp_mkey = @emp_card_no
Select @TotalRecord = ((1.75 * 6) / @Total_days) * (@Days_worked + @Final_PaidDayLop)
from emp_mon_day a where a.emp_mkey = @emp_card_no group by a.emp_mkey
PRINT 'Final Paid LOP ' + cast(coalesce(@Final_PaidDayLop,0) as char)
PRINT 'Total Record ' + cast(coalesce(@TotalRecord,0) as char)
FETCH NEXT FROM daily_Allocate INTO
@emp_card_no, @emp_name, @Dt_Of_Join
END
CLOSE daily_Allocate
DEALLOCATE daily_Allocate
END END
which gives me output as below
Now what I want is, I want to insert the above data into the temp table.
I tried like below
CREATE TABLE #tmp1111
(
Sr_no int identity(1,1),
Current_Status nvarchar(255),
Emp_card_no int,
Total_days int,
days_worked int,
final_lop_paid int,
total_record int
)
First I created a temp table and tried to insert the data as below
INSERT INTO #tmp1111 exec Leave_Allocation_Mar_2016 'C', '2', '2016'
It executed succesfully but when I ran the select statement there were no records in the temp table.
I am using SQL server 2005
Aucun commentaire:
Enregistrer un commentaire