SELECT works, but UPDATE does not.
Every version of CAST and CONVERT
I'm getting this error:
Arithmetic overflow error converting int to data type numeric
When I try to do this:
$sql = "UPDATE rentinc ".
"SET curr_loss_mo = ROUND(CONVERT(numeric(3,0), DATEDIFF(DAY, missincdate, GETDATE()) / 30), 0) ".
"WHERE months2 > 12";
I'm pretty sure there's overkill in the code above, but I was trying EVERYTHING.
I can go to SSMS and run this SELECT:
SELECT curr_loss_mo, ROUND(CONVERT(numeric(3, 0), DATEDIFF(DAY, missincdate, GETDATE()) / 30), 0) AS DateNumCalc
FROM rentinc
WHERE months2 > 12
And it works fine. And the two columns look exactly the same! The curr_loss_mo field is a numeric(3,0) and there are no values in the table that will try to update with more than three characters.
So why am I getting this error?
"Arithmetic overflow error converting int to data type numeric"
WHEREconditions on the two queries. Try using the same condition inMMS, it's probably a case wherecurr_loss_mo IS NULLwhich is causing your problem - Nicknumeric(3,0)for all values ofmissincdatebetween July 12, 1937 and Oct 19, 2101 (as of roughly today.) Since the error indicates that a conversion fromintis the one causing a problem, I do think it has to be caused by theround()function. What is the column type for your date value? As already pointed out the filters are not the same. Do you have any blanks or zeroes being treated as Jan 1, 1900? - shawnt00rentincandtemp_rentincare different tables. Do they have the same schema? - AlwaysLearning