0
In the script below when one task is completed the other will open on the first working day of the following month.
Example: Task 10 was completed on the day 18-11-2016
, then another will be generated in the day 01-12-2016
. The field that will have that date is the EstTarData
as it is in the script where I put getdate() + 30
.
Obs: I also already have a useful days function calculating correctly.
Function:
USE [0800net_PRD]
GO
/****** Object: UserDefinedFunction [dbo].[dias_uteis] Script Date: 25/09/2017 10:11:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[dias_uteis] (@DATA_INICIAL DATETIME, @DATA_FINAL
DATETIME)
RETURNS INT
AS
BEGIN
DECLARE @CONT INT
SET @DATA_INICIAL = (SELECT CAST(@DATA_INICIAL AS DATE) )
SET @DATA_FINAL = (SELECT CAST(@DATA_FINAL AS DATE ))
SET @CONT = 0
WHILE (@DATA_INICIAL <= @DATA_FINAL)
BEGIN
IF (DATEPART(DW, @DATA_INICIAL ) IN(1,7) OR @DATA_INICIAL IN (SELECT CAST(FerData AS DATE) FROM Feriado))
BEGIN
SET @DATA_INICIAL = @DATA_INICIAL+1
END
IF DATEPART(DW, @DATA_INICIAL ) NOT IN(1,7)
BEGIN
SET @CONT = @CONT+1
SET @DATA_INICIAL = @DATA_INICIAL+1
END
END
RETURN @CONT
END
IF (SELECT TarStatus FROM Tarefa WHERE TarID = @Tarefa) = 9
BEGIN
UPDATE EstoqueTarefa SET Ativo = 1 WHERE EstTarID IN (246,569) and EstTarData = getdate() + 30 END
END;
But in your case you’re making one
UPDATE
. That’s right?– Sorack
That’s right @Sorack
– Renan Bessa
@Caiqueromero, it’s a real update, it’s a rule within our system. Regarding the function of useful days, this is not the case, I just commented pq exists and wanted to put it inside this script to generate the next task only on the first useful day of the following month.
– Renan Bessa
@Caiqueromero, I edited the question. I put the function.
– Renan Bessa
@Renanbessa in the Task table you store the date it was finalized?
– Caique Romero
Yes @Caiqueromero, it’s the Tarfechamento field
– Renan Bessa