June 16, 2015 at 1:38 pm
I'm knew to Sql, I've tried many variations, and I keep getting errors, assistance would be greatly appreciated;
CAST(ROUND(IP_BLa.MEAS_VALUE-32)*5/9,2)
CAST(ROUND(IP_BLa.MEAS_VALUE-32)*5/9,2)as decimal(3,2))
June 16, 2015 at 3:17 pm
You need to pay more attention to details.
You are missing one parenthesis in your second option and the target data type in the first one.
The precision in decimal indicates the full number of digits, not only the ones on the left.
Finally, you want to be sure to prevent integer division for accurate results.
CREATE TABLE IP_BLa(
MEAS_VALUE int)
INSERT INTO IP_BLa
VALUES(50), (60), (70), (80), (90), (100);
--Added one parenthesis and used a larger decimal precision
SELECT CAST(ROUND((IP_BLa.MEAS_VALUE-32.)*5/9,2) as decimal(6,2)), --using decimals by adding a point to 32 (converts it to float)
CAST(ROUND((IP_BLa.MEAS_VALUE-32)*5/9,2)as decimal(6,2)) --using integer division
FROM IP_BLa
GO
DROP TABLE IP_BLa
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply