1
I got the following SELECT
in SQL Server:
SELECT
th.CidadeCod,
th.ContratoCod,
CONVERT(DECIMAL(5,2), ( SUM(th.PlacasLidas)/SUM(th.Trafego) ) * 100) AS [IndiceOCR]
FROM
controle.TrafegoFaixaHora th
INNER JOIN ssis.Contratos c ON th.ContratoCod = c.ContratoCod AND th.CidadeCod = c.CidadeCod
INNER JOIN controle.Equipamentos e ON th.ContratoCod = e.ContratoCod AND th.CidadeCod = e.CidadeCod
WHERE
c.FlagAtivo = 1 AND e.FlagOcr = 1
GROUP BY
th.CidadeCod,
th.ContratoCod
But the error is returned:
Msg 8115, Level 16, State 2, Line 2
Arithmetic overflow error converting expression to data type int.
What should I do ?
is returning a value greater than 5 (including the whole part and decimal digits) in the calculation you are trying to convert. See the result of
( SUM(th.PlacasLidas)/SUM(th.Trafego) ) * 100
. Return it without theconvert
to see the value size, hence you adjust the size of thedecimal
correctly– Ricardo Pontual
the Placaslides and Trafego fields are of what type?
– Marco Souza