Click here to Skip to main content
15,900,461 members

Comments by Tan Chee Yong (Top 3 by date)

Tan Chee Yong 8-Oct-20 22:34pm View    
you can use something like
SET @StartDate = (SELECT School_update FROM Application_Status);
Tan Chee Yong 8-Oct-20 6:45am View    
If the non-working is in a table and the 30 and 5 are calendar days, you can try the below sql code

DECLARE @StartDate DATE
SET @StartDate = '20201007'

DECLARE @ServiceType INT;
SET @ServiceType = 1;

DECLARE @NoOfWorkingDays INT;
If @ServiceType = 1
	SET @NoOfWorkingDays = 30
ELSE 
	SET @NoOfWorkingDays = 5;

DECLARE @Counter INT; 
DECLARE @DayAdd INT; 
SET @DayAdd =1;

DECLARE @CurrDate datetime;
SET @CurrDate = DATEADD(DAY,@NoOfWorkingDays,@StartDate);

IF (@CurrDate IN (SELECT Date_FMT FROM TBL_Holidays))
BEGIN
	SET @CurrDate = DATEADD(DAY,1,@CurrDate);
	WHILE (@CurrDate IN (SELECT Date_FMT FROM TBL_Holidays))
	BEGIN
		SET @CurrDate = DATEADD(DAY,1,@CurrDate);
	END
END
SELECT @CurrDate;
Tan Chee Yong 8-Oct-20 6:09am View    
I will assume the 30 days and 5 days are working days. If they are calendar days, do a dateadd function and check whether it is a working day and not in holiday table, if not valid, do a looping by adding 1 day each time to check until it is a working day