I obtain on my SQL Server 2005 an error
Server: Msg 8115,
Arithmetic overflow error converting numeric to data type numeric.
When I try to insert a value = X
(DECIMAL(3,2)) * Y
(INT)
in a column MYCOLUMN
typed DECIMAL (10,3)
How to workaround this problem?
UPDATE
some code bellow to understand the situation
-- ============================================================
-- Table : GP_WGENTH
-- ============================================================
CREATE TABLE #GP_WGENTH
(
KEYINTERNAL CHAR(32) NOT NULL,
KEYHOUR INT NOT NULL,
FIRM CHAR(5) NOT NULL,
CENTRE CHAR(2) NOT NULL,
SERVICE CHAR(6) NOT NULL,
AGENT CHAR(5) NOT NULL,
VERSION VARCHAR(3) NOT NULL,
DATE_ROULEMENT DATETIME NOT NULL,
SERVICEINSTANCE SMALLINT NOT NULL,
TYPEHOUR CHAR(9) NOT NULL,
QUANTITEFIXE DECIMAL(12,2) NULL ,
TYPECMP INT NULL ,
PERCENTCALC DECIMAL(3,2) NULL
)
-- ============================================================
-- Table : GP_WGENSVCTH
-- ============================================================
CREATE TABLE #GP_WGENSVCTH
(
KEYINTERNAL CHAR(32) NOT NULL,
KEYHOUR INT NOT NULL,
FIRM CHAR(5) NOT NULL,
CENTRE CHAR(2) NOT NULL,
SERVICE CHAR(6) NOT NULL,
AGENT CHAR(5) NOT NULL,
VERSION VARCHAR(3) NOT NULL,
DATE_ROULEMENT DATETIME NOT NULL,
SERVICEINSTANCE SMALLINT NOT NULL,
TYPEHOUR CHAR(9) NOT NULL,
VALUE DECIMAL(10,3) NOT NULL
)
GO
INSERT INTO #GP_WGENSVCTH
(KEYINTERNAL,
KEYHOUR,
FIRM,
CENTRE,
SERVICE,
AGENT,
VERSION,
DATE_ROULEMENT,
SERVICEINSTANCE,
TYPEHOUR,
VALUE)
SELECT WTH.KEYINTERNAL,
WTH.KEYHOUR,
WTH.FIRM,
WTH.CENTRE,
WTH.SERVICE,
WTH.AGENT,
WTH.VERSION,
WTH.DATE_ROULEMENT,
WTH.SERVICEINSTANCE,
WTH.TYPEHOUR,
WTH.PERCENTCALC * SUM(SC.LENGTH) -- !!! BOOOM !!!!!!!!! HERE
FROM #GP_WGENTH WTH
INNER JOIN GP_SERVICE_HABILLAGE_COMPONENT SC
ON WTH.FIRM = SC.FIRM
AND WTH.CENTRE = SC.CENTRE
AND WTH.SERVICE = SC.SERVICE
AND WTH.VERSION = SC.VERSION
AND WTH.TYPECMP = SC.TYPECMP
WHERE WTH.KEYINTERNAL = 'august 23 2012 10:45:21:027PM '
AND SC.LENGTH IS NOT NULL
GROUP BY WTH.KEYINTERNAL,
WTH.KEYHOUR,
WTH.FIRM,
WTH.CENTRE,
WTH.SERVICE,
WTH.AGENT,
WTH.VERSION,
WTH.DATE_ROULEMENT,
WTH.SERVICEINSTANCE,
WTH.TYPEHOUR,
WTH.PERCENTCALC
DECIMAL(10,3)
isn't large enough. We can't tell you what's right unless you tell us the maximum values for X and Y. – BratislavaDECIMAL(10,3)
? – BratislavaDECIMAL(10,3)
? – Bratislava1 111 111 111,111
– ShrumDECIMAL(10,3)
. And why do you think the max value of Y isn't important? We need to know what the max value of the product will be in order to tell you which data type and with what precision / scale you should be using. Multiplying a large value by 10 vs. 50000 vs. 1 billion (all valid values for Y since it's an INT), the capacity you need is quite different. If I told you to go buy some beer for my company picnic, wouldn't you be interested in how many employees I have, and how many beers per person? – Bratislava1 111 111,111
– Shrum