I created a function to use in a View, works similar to DATEADD but only with my company's Business days Monday-Thursday.I am running a query but it never ends to run.This is the function:USE [RA_dev]GO/****** Object: UserDefinedFunction [Production].[GBDATEADD] Script Date: 4/11/2015 5:58:19 PM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: Roberto Armenta-- Create date: 4/11/2015-- Description: Gulfstream Business Date Add-- =============================================ALTER FUNCTION [Production].[GBDATEADD] ( @FromDate datetime, @DaysToAdd int)RETURNS datetimeASBEGIN DECLARE @Result datetime DECLARE @Counter as int DECLARE @DayEvaluated as datetime SET @DayEvaluated = DATEADD(Day,1,@FromDate) SET @COUNTER = 0 WHILE @Counter < @DaysToAdd BEGIN SET @COUNTER = @COUNTER + CASE DATEPART(WEEKDAY,@DayEvaluated) WHEN 2 THEN 1 WHEN 3 THEN 1 WHEN 4 THEN 1 WHEN 5 THEN 1 ELSE 0 END IF CASE DATEPART(WEEKDAY,@DayEvaluated) WHEN 2 THEN 1 WHEN 3 THEN 1 WHEN 4 THEN 1 WHEN 5 THEN 1 ELSE 0 END = 1 BEGIN SET @Result = @DayEvaluated END SET @DayEvaluated = DATEADD(Day,1,@DayEvaluated) END RETURN @ResultEND
This is how I am trying to use it in the View:Production.GBDATEADD(Production.Schedule.START_DATE, Production.Operations_Data_Pool.MFG_DAY - 1) AS SCH_DATE
Please I would appreciate anyone's help.Best Regards,Roberto ArmentaIndustrial EngineerAdvanced Aircraft ProgramsGulfstream Aerospace Corporationroberto.armenta@gulfstream.com