I have a table with the followin columns:
(StartDate, EndDate and BusinessDays)
The BusinessDays colums is to be calculated using the scalar function called GetBusinessDays; however Im relatively green at sql programming and not sure how to call these the tables fiels in a procedure and apply the GetBusiness Days function to insert the calculated BusinessDays in the BusinessDays column of my table. Any help would be appreciated as i have tried but failed.
My GetBusinessDays function looks as follows:
USE [ProjCoorTools]
GO
/****** Object: UserDefinedFunction [dbo].[GetBusinessDays] Script Date: 12/10/2009 09:20:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[GetBusinessDays]
(
@StartDate datetime,
@EndDate datetime
)
returns int
as
begin
declare @DaysBetween int
declare @BusinessDays int
declare @Cnt int
declare @EvalDate datetime
select @DaysBetween = 0
select @BusinessDays = 0
select @Cnt=0
select @DaysBetween = datediff(Day,@StartDate,@endDate) + 1
while @Cnt < @DaysBetween
begin
select @EvalDate = @StartDate + @Cnt
if (dbo.IsDateAHoliday(@EvalDate) = 0)
BEGIN
if ((datepart(dw,@EvalDate) <> 1) and (datepart(dw,@EvalDate) <> 7))
BEGIN
select @BusinessDays = @BusinessDays + 1
END
END
select @Cnt = @Cnt + 1
end
return @BusinessDays
end
(StartDate, EndDate and BusinessDays)
The BusinessDays colums is to be calculated using the scalar function called GetBusinessDays; however Im relatively green at sql programming and not sure how to call these the tables fiels in a procedure and apply the GetBusiness Days function to insert the calculated BusinessDays in the BusinessDays column of my table. Any help would be appreciated as i have tried but failed.
My GetBusinessDays function looks as follows:
USE [ProjCoorTools]
GO
/****** Object: UserDefinedFunction [dbo].[GetBusinessDays] Script Date: 12/10/2009 09:20:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[GetBusinessDays]
(
@StartDate datetime,
@EndDate datetime
)
returns int
as
begin
declare @DaysBetween int
declare @BusinessDays int
declare @Cnt int
declare @EvalDate datetime
select @DaysBetween = 0
select @BusinessDays = 0
select @Cnt=0
select @DaysBetween = datediff(Day,@StartDate,@endDate) + 1
while @Cnt < @DaysBetween
begin
select @EvalDate = @StartDate + @Cnt
if (dbo.IsDateAHoliday(@EvalDate) = 0)
BEGIN
if ((datepart(dw,@EvalDate) <> 1) and (datepart(dw,@EvalDate) <> 7))
BEGIN
select @BusinessDays = @BusinessDays + 1
END
END
select @Cnt = @Cnt + 1
end
return @BusinessDays
end