0
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 [HORPDB00\PDBSIAC].[SiacPRD].[dbo].[IntPluProduto] p
INNER JOIN [HORPDB00\PDBSIAC].[SiacPRD].[dbo].[IntControle] c on c.idProcesso = p.idProcesso
LEFT JOIN [HORPDB00\VANR].[tlmark].[dbo].[Produto] vanProduto on vanProduto.CdPrdSAP = p.codInterno
LEFT JOIN tbFabricante f on f.idFabricante = CAST(vanProduto.CdFbr AS int)
WHERE NOT EXISTS(select 1 from tbProduto where idSAP = p.codInterno)
AND vanProduto.cdFbr <> 'NNN0'
AND CAST(c.dtHrProcesso AS DATE) > DATEADD(ss, 64800, DATEADD(d, -1, CAST(CONVERT(varchar(10), GETDATE(), 103) AS smalldatetime)))
OR CAST(c.dtHrProcesso AS DATE) = CAST(GETDATE() AS DATE)
AND c.codModulo = 14
AND vanProduto.ICMSubst <> 'T'
At this point:
AND CAST(c.dtHrProcesso AS DATE) > DATEADD(ss, 64800, DATEADD(d, -1, CAST(CONVERT(varchar(10), GETDATE(), 103) AS smalldatetime)))
OR CAST(c.dtHrProcesso AS DATE) = CAST(GETDATE() AS DATE)
The above filter does nothing but, starting from the current date, subtracts 1 day, and then adds 18 hours (64800 seconds). For example, for the current date 27/12/2016 06:00:00: Subtract 1 day: 26/12/2016 06:00:00 Format result to: 26/12/2016 00:00:00 Add 64800 seconds (18hrs): 26/12/2016 18:00:00
Conversion error: The Conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.
--test, earlier date from 18:00 SELECT DATEADD(ss, 64800, DATEADD(d, -1, CAST(CONVERT(varchar(10), GETDATE(), 120) AS smalldatetime)))
– Harry
Do not understand, you want me to test this line? Here returned 2016-12-26 18:00:00
– Ricardo Pontual