I am getting this error in SQL Server:
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.
when running this query:
SUM(CASE WHEN t.type = 'doc' THEN t.id ELSE 0 END) AS DocType,
SUM(CASE WHEN t.type = 'pdf' THEN t.id ELSE 0 END) AS PdfType
Type is varchar and id is int.
I tried with SUM(CASE WHEN t.type = 'doc' THEN ISNULL(t.id, 0) ELSE 0 END) AS DocType
but that's not working.
What am I missing ?
SUMreturns the data type of the input expression, which in this case appears to be aint. perhaps the sum of your columnID(seems odd you're summing the value of your ID's) is greater than 2,147,483,647. TryCASE WHEN t.type='doc' THEN CONVERT(bigint,t.id) ELSE 0 ENDDoes that work?DocTypeandPdfType- What's logic behind your query? Are you trying count the number of records of type Doc and Pdf?COUNT?