Hello All! My stored procedure works to calculate total number of days of Holidays taken eliminating Weekends & Other type of holidays from the calculation which is what I want. I now want to work on the existing logic which does a comparison with the current date & shows how many days have already been taken and the ones that have entries in the database but based on the current date they haven't been taken. Such as if there is an entry scheduled for December 12th & today is August 16th, obviously it hasn't been used. This is my stored procedure: ALTER Proc [dbo].[Holidays] @UserID intAS------VARIABLESDECLARE @Hol float,@HolLeft float------CREATE TABLECREATE TABLE #tmpHolidays(HolStartDate datetime,HolEndDate datetime, TotalHol float, TotalVacLeft float,)------------INSERT INTO THE TABLEINSERT INTO #tmpHol(HolStartDate, HolEndDate, TotalHol)SELECT HolStartDate, HolEndDate, CASE Type WHEN 0.5 THEN (Datediff (d, HolStartDate, HolEndDate) + 0.5) - (select count (*) from dbo.Weekends where dbo.Weekends.pPeriod >= dbo.Info. HolStartDate AND dbo.Weekends.pPeriod <= dbo.Info. HolEndDate) ELSEDatediff (d, HolStartDate, HolEndDate + 1) - (select count (*) from dbo.Weekends where dbo.Weekends.pPeriod >= dbo.Info. HolStartDate AND dbo.Weekends.pPeriod <= dbo.Info. HolEndDate) ENDfrom dbo.InfoWHERE UserID = @UserID And HolType = 'Holiday'SET@TotalHol = (Select Sum(TotalHol) from #tmpHol)SET @TotalHolLeft = (Select TotalHol from dbo.Users WHERE UserID = @UserID) - @TotalHolSelect @TotalHol AS TotalDaysOff, @TotalHolLeft AS TotalHolLeft-----------DROP TABLEDROP TABLE #tmpHol
Any ideas? Thanks