0
I have a Job in sql server that runs twice a day, 06:00 and 18:00, it has an sql query where I take the date of the process and compare with the date of the day. It turns out that if you have a new change after 18:00, these will not be updated because it will be a new date after 24:00. How could I make up this time in hours on the query by adding this result? I could change the job schedule but the client thinks no, that I wanted another solution, I can’t see a solution. The c.dtHrProcess field has the date in the format : 2016-11-23 04:38:10.307
Segue a consulta
SELECT DISTINCT p.codInterno,
CASE
WHEN f.idFabricante IS NULL THEN 99999999999999
ELSE f.idFabricante
END AS fabri,
'0',
p.descResumida,
p.descProduto,
p.descProduto,
p.codElemento,
GETDATE(),
GETDATE(),
0,
0
FROM [192.168.200.87].[siac].[dbo].[IntPluProduto] p
INNER JOIN [192.168.200.98].[siac].[dbo].[IntControle] c on c.idProcesso = p.idProcesso
LEFT JOIN [192.168.0.150].[tlmark].[dbo].[Produto] vanProduto on vanProduto.CdPrdSAP = p.codInterno
LEFT JOIN tbFabricante f on f.idFabricante = CAST(vanProduto.CdFbr AS INT)
WHERE (select COUNT(*) from tbProduto where idSAP = p.codInterno) = 0
AND vanProduto.cdFbr <> 'NNN0'
AND CAST(c.dtHrProcesso AS DATE) = CAST(GETDATE() AS DATE)
AND c.codModulo = 14
AND vanProduto.ICMSubst <> 'T'
Have you thought about saving the date/time of the last execution of JOB in the database? So you could filter only processes that have an equal or longer date (>=) to the last execution date.
– E.Thomas
How could I do that?
– Harry