|
umar
Starting Member
6 Posts |
Posted - 2009-01-22 : 05:54:35
|
| this is ma procedureALTER PROCEDURE [dbo].[lntsp_Csti_Hr_Stipend_Last_Report](@Trade_Code varchar(15)=null,@CstiCode VARCHAR(15)= NULL,@SelYear int=null,@SelMonth int=null,@SelFN int=null,@StipendFrom VARCHAR(50)= NULL,@StipendTo VARCHAR(50)= NULL,@LeavingDate varchar(50)=null,@uid int=0,@error VARCHAR(100)=null OUTPUT)ASSET NOCOUNT ON/* Created By : umarCreated On : 2-jan-2009Purpose : lntsp_Csti_Hr_Stipend_Last_Report*/BEGIN---Creating Temparay table for finding Extra holiday based on P&ODcreate table #temp_Extra_Holiday_L(trainee_Id varchar(15),Extra_Holiday int)----get set of trainee id based conditiondeclare @TraineeID varchar(15)declare @ExdL intselect REPLACE(CONVERT(CHAR(11), holiday_date, 113),space(1),'-') as holiday_date into #Csti_Hr_Holiday_Master1 from Csti_Hr_Holiday_Master where csticode=@CstiCode and (holiday_date BETWEEN @StipendFrom and @StipendTo)DECLARE @NoofDays intset @NoofDays = datediff(dd ,@StipendFrom ,@StipendTo)+1insert into #Csti_Hr_Holiday_Master1 (holiday_date)select REPLACE(CONVERT(CHAR(11), DATEADD(dd, M.number-1, @StipendFrom), 113),space(1),'-')FROM master..spt_values AS MWHERE M.type = 'P' and datename(dw,DATEADD(dd, M.number-1, @StipendFrom))='Sunday' andM.number BETWEEN 1 AND @NoofDays select distinct(holiday_date) into #Csti_Hr_Holiday_Master from #Csti_Hr_Holiday_Master1select tr.trainee_id into #temp_trainee_id_GRLfrom Csti_Hr_Trainees tr where tr.Joined_Csti_Code=@CstiCode and tr.joined_trade_code=@Trade_Code and ((@StipendFrom between tr.Joining_Date and tr.Leaving_Date) OR (@StipendTo between tr.Joining_Date and tr.Leaving_Date)) and (tr.leaving_date between @StipendFrom and @StipendTo)and tr.leaving_date=@LeavingDate----ctreate cursor for that set of trainee id declare cursor_tid cursor forselect trainee_id from #temp_trainee_id_GRL order by trainee_id--open & fetch cursoropen cursor_tidfetch cursor_tid into @TraineeID --FETCH NEXT FROM cursor_po INTO @po_codewhile (@@FETCH_STATUS = 0)begin--print @TraineeID----get set of Absent date based conditiondeclare @Absent_dateL varchar(50)declare @tcL intset @ExdL=0select Absent_date into #temp_absent_date_Lfrom Csti_Hr_Trainee_Absent_Register tr wheretr.trainee_id=@TraineeID AND (Absent_date BETWEEN @StipendFrom and @StipendTo)-- DECLARE @NoofDays int-- set @NoofDays = datediff(dd ,@StipendFrom ,@StipendTo)+1---- insert into #temp_absent_date_L (Absent_date)-- select REPLACE(CONVERT(CHAR(11), DATEADD(dd, M.number-1, @StipendFrom), 113),space(1),'-')-- FROM master..spt_values AS M-- WHERE M.type = 'P' and datename(dw,DATEADD(dd, M.number-1, @StipendFrom))='Sunday' and-- M.number BETWEEN 1 AND @NoofDays ----ctreate cursor for that set of Absent datesdeclare cursor_ad cursor forselect Absent_date from #temp_absent_date_L order by Absent_date --open & fetch cursoropen cursor_adfetch cursor_ad into @Absent_dateL while (@@FETCH_STATUS = 0)begin--print @Absent_dateLDECLARE @FlagL INTSET @FlagL = 0declare @holiday_dateL datetimeset @holiday_dateL=dateadd(day,1,@Absent_dateL)IF(select holiday_date from #Csti_Hr_Holiday_Master where holiday_date=@holiday_dateL ) IS NOT NULL --csticode=@CstiCode and and (holiday_date BETWEEN @StipendFrom and @StipendTo)BEGINWHILE (select holiday_date from #Csti_Hr_Holiday_Master where holiday_date=@holiday_dateL) is not null --csticode=@CstiCode and BEGINSET @FlagL = @FlagL + 1set @holiday_dateL=dateadd(day,1,@holiday_dateL)END-- PRINT '-FINAL'if(select Absent_date from Csti_Hr_Trainee_Absent_Register where trainee_id=@TraineeID and Absent_date=@holiday_dateL) is null-- PRINT @FlagL-- ELSE-- SET @FlagL=0beginSET @FlagL=0endEND--print @FlagL--------------extra--Add the number of extra daysset @ExdL=@ExdL+@FlagLFETCH NEXT FROM cursor_ad INTO @Absent_dateL --select @TraineeID,@FlagLendclose cursor_addeallocate cursor_addrop table #temp_absent_date_L--print @ExdL-------total extra--insert Extra days into temp table insert into #temp_Extra_Holiday_Lselect @TraineeID,@ExdLFETCH NEXT FROM cursor_tid INTO @TraineeIDend--close the cursorclose cursor_tiddeallocate cursor_tid |
|