SQLTeam.com | Weblogs | Forums

SQL Server batch and select output difference in decimal point

Following batch statement if i execute in SSMS giving me Result like given below

DECLARE @M_TUBE_VOLUME NUMERIC(38,10),
@M_TUBE_OD NUMERIC(38,10)=12.50000,
@M_TUBE_ID NUMERIC(38,10)=12.50000,
@M_TUBE_LEN NUMERIC(38,10)=4000.00000,
@M_TUBE_COUNT NUMERIC(38,10)=212.4215000,
@M_S_TUBE_LEN NUMERIC(38,10)=0.0000,
@M_S_TUBE_COUNT NUMERIC(38,10)=3587.000

SET @M_TUBE_VOLUME=(SELECT 3.141592 / 4 * @M_TUBE_OD * @M_TUBE_ID * ((@M_TUBE_LEN * @M_TUBE_COUNT) + (@M_S_TUBE_LEN * @M_S_TUBE_COUNT)));

SELECT @M_TUBE_VOLUME

RESULT -- 104272138.7104680000

and if i execute same thing in SSMS using select statement

SELECT 3.141592 / 4 * 12.5000000000 * 12.5000000000 * ((4000.0000000000 * 212.4215000000) + (0.0000000000 * 3587.0000000000))

RESULT -- 104272138.285625000000000000000

Why two result are different any reason please help me

Rounding

SELECT CAST(3.141592 AS NUMERIC(38,10)) / 4 * CAST(12.5000000000 AS NUMERIC(38,10)) * CAST(12.5000000000 AS NUMERIC(38,10)) * ((CAST(4000.0000000000 AS NUMERIC(38,10)) * CAST(212.4215000000 AS NUMERIC(38,10))) + (CAST(0.0000000000 AS NUMERIC(38,10)) * CAST(3587.0000000000 AS NUMERIC(38,10))))