Arithmetic overflow error converting expression to int data type

I have a problem with the request below. The problem is this:

Msg 8115, Level 16, State 2, Line 1 Arithmetic overflow error converting expression to int data type

The problem is in this line of code below.

INNER JOIN Test t ON a.AccountNO <> t.AccountNo

Any ideas?

WITH TEST AS
(
    SELECT DISTINCT AccountNo, SUBSTRING(APartyNO, 3, LEN(APartyNo)) AS APartyNoCut
    FROM (SELECT DISTINCT AccountNo, APartyNo 
            FROM prf_BatchItems 
           WHERE BatchID = 127 
             AND Code1 = 'DEDF' 
             AND APartyNo NOT LIKE '04%'
             AND (   Left(APartyNo,2) = '02' 
                  OR Left(APartyNo,2) = '03' 
                  OR Left(APartyNo,2) = '07'
                  OR Left(APartyNo,2) = '08')
        GROUP BY AccountNo, APartyNo
    UNION
    SELECT DISTINCT AccountNo, APartyNo 
      FROM prf_BatchItemAdditionalAPartyNos 
     WHERE BatchID = 127 
  GROUP BY AccountNo, APartyNo) a
)
SELECT Code2, TypeName, CallTypeName, --SUM([Count]), 
        SUM(Duration), SUM(CostGrossExGST)
FROM
( 
    SELECT 'WITHOUT STD' AS Type, 
            Code2, b.TypeName, CallTypeName,
            --SUM([COunt]) AS Count,  
            SUM(DurationSecond) AS Duration, 
            SUM(a.CostGrossExGSt) AS CostGrossExGST 
    FROM prf_BatchItems a 
            INNER JOIN (SELECT * FROM dbo.prf_BillTypeCodes WHERE BillTypeID = 2)  b ON a.Code2 = b.BillCodeName
            INNER JOIN Test t ON a.AccountNO <> t.AccountNo 
    where BatchID = 127 
            AND Code1 = 'DC'  
            AND ServiceTypeName = 'MobileNet' 
            AND CallTypeName = 'National Direct Dialled calls'
            AND (LEFT(BPartyNo,2) <> '02' AND LEFT(BPartyNo,2) <> '03' OR LEFT(BPartyNo,2) <> '07' OR LEFT(BPartyNo,2) <> '08')
            AND BPartyNo NOT LIKE '04%'
            AND BPartyNo NOT LIKE '1%'
    GROUP BY --a.AccountNo, 
            Code2,  b.TypeName, CallTypeName) zz 
GROUP BY Code2,  TypeName, CallTypeName
+3
source share
2 answers

looks like one of AccountNO in this line is INNER JOIN Test t ON a.AccountNO <> t.AccountNonot an integer and has a value that cannot be converted to an integer

what is the data type of the column in both tables

+3
source

sql , , int (integer) Bigint, .

0

Source: https://habr.com/ru/post/1758830/


All Articles