Hey Everyone! I need help with a stored procedure that I am trying to formulate, I have two stored procedures that work the way I want it to but I want to break the results down further with no luck. One stored procedure gives a list of all the records with all the dates specified. The Second stored procedure takes a total of all the days depending on the VacationType & gives the total figure. I need to formulate a stored procedure that will give the total numbers of days taken off for each record & not the whole combined. Here are my two stored procedures: Stored Procedure #1Stored Procedure #1ALTER PROCEDURE [dbo].[VDisplay]@ID intASSelect RecordID, AssociateID, EmployeeName, StartDate, EndDate, VacationType, DayType =Case DayTypeWhen 0.5 THEN 'Half Day' ELSE'Full Day'ENDfrom dbo. InfoWhere ID=@ID
Stored Procedure #2ALTER Proc [dbo].[VTotal] @ID intAS------VARIABLESDECLARE @TotalVac float,@TotalVacLeft float------CREATE TABLECREATE TABLE #tmpDisplay(StartDate datetime,EndDate datetime, TotalVac float, TotalVacLeft float,)----------SET VARIABLES------------INSERT INTO TABLEINSERT INTO #tmpDisplay(StartDate, EndDate, TotalVac)SELECT StartDate, EndDate, CASE DayType WHEN 0.5 THEN (Datediff (d, StartDate, EndDate) + 0.5) - (select count (*) from Vac.CustomHolidays where Vac.CustomHolidays.Period >= dbo.Info.StartDate AND Vac.CustomHolidays.Period <= dbo.Info.EndDate) ELSEDatediff (d,StartDate,EndDate + 1) - (select count (*) from Vac.CustomHolidays where Vac.CustomHolidays.Period >= dbo.Info.StartDate AND Vac.CustomHolidays.Period <= dbo.Info.EndDate) ENDfrom dbo.InfoWHERE ID = @ID And VacationType = 'Vacation'SET@TotalVac = (Select Sum(TotalVac) from #tmpDisplay)SET @TotalVacLeft = (Select TotalVac from dbo.Users WHERE ID = @ID) - @TotalVacSelect @TotalVac AS TotalDaysTaken, @TotalVacLeft AS TotalDaysLeft-----------DROP TABLEDROP TABLE #tmpDisplay
To better illustrate here's an image of the desired result with sample data[url]http://imageshack.us/f/806/sampledata.jpg/[/url]
[/URL][/img]