Arithmetic overflow error Converting Expression to data type int in Count

Asked

Viewed 2,808 times

-1

I’ve seen several responses to that message

Arithmetic overflow error Converting Expression to data type int.

However, everything they indicated to do did not work. It only gives error when using the count.

Code:

SELECT 
    COUNT(DML.NK_CO_SEQ_LOTERICA)
FROM DW_XCAP.XCAP.DM_LOTERICA AS DML
JOIN DW_XCAP.XCAP.DM_PEDIDO AS DMP ON DMP.CO_LOTERICA = DML.CO_LOTERICA
JOIN DW_XCAP.XCAP.DM_PRODUTO AS DMPR ON DMPR.NK_CO_SEQ_PRODUTO = DML.CO_PRODUTO
JOIN DW_XCAP.XCAP.DM_ATENDIMENTO AS DMA ON DMA.CO_LOTERICA = DMP.CO_LOTERICA
JOIN DW_XCAP.XCAP.DM_TITULO AS DMT ON DMT.CO_PRODUTO = DML.CO_PRODUTO AND DMT.CO_LOTERICA = DML.CO_LOTERICA
JOIN DW_XCAP.XCAP.DM_LOG_ENTRADA AS DME ON DME.CO_PRODUTO = DML.CO_PRODUTO
WHERE DML.CO_PRODUTO IS NOT NULL
AND DME.CO_PRODUTO <> 0
  • The types of the fields they link to are the same?

  • SELECT COUNT(DISTINCT DML.NK_CO_SEQ_LOTERICA)

  • See if there is an improper Cartesian product generating a value of "Count" "explosive"

2 answers

0

Try to use the COUNT_BIG

SELECT 
    COUNT_BIG(DML.NK_CO_SEQ_LOTERICA)
FROM DW_XCAP.XCAP.DM_LOTERICA AS DML
JOIN DW_XCAP.XCAP.DM_PEDIDO AS DMP ON DMP.CO_LOTERICA = DML.CO_LOTERICA
JOIN DW_XCAP.XCAP.DM_PRODUTO AS DMPR ON DMPR.NK_CO_SEQ_PRODUTO = DML.CO_PRODUTO
JOIN DW_XCAP.XCAP.DM_ATENDIMENTO AS DMA ON DMA.CO_LOTERICA = DMP.CO_LOTERICA
JOIN DW_XCAP.XCAP.DM_TITULO AS DMT ON DMT.CO_PRODUTO = DML.CO_PRODUTO AND DMT.CO_LOTERICA = DML.CO_LOTERICA
JOIN DW_XCAP.XCAP.DM_LOG_ENTRADA AS DME ON DME.CO_PRODUTO = DML.CO_PRODUTO
WHERE DML.CO_PRODUTO IS NOT NULL
AND DME.CO_PRODUTO <> 0

0

This error happens when the value exceeds the specified column size.

An example of how this error happens: You have 3 columns (c1, c2 and c3) defined as INTEGER, c1 = ([c2]*[c3]). If the data in c2 and/or c3 are very large values, c1 will exceed the permitted limit for INTERGER and you’ll get this mistake.

To fix this error, you have to check the size of the destination column. A tip is to reduce the allowed values in the source columns of the formula or increase the size of the target column.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.