Wednesday, 28 July 2021

SQL integer integer division, and integer decimal Division

 https://stackoverflow.com/questions/3443672/integer-division-in-sql-server


SELECT cast(151/6 AS DECIMAL(9,2))
SELECT 151/6

NOTE the above two commands will product integer result as 151 is integer and 6 is integer, 151/6 will produce integer 25

For SQL to get decimal result, at least one of the numeber has to be decimal 

SELECT 151/CAST(6 AS DECIMAL (9,2))




No comments:

Post a Comment