decimals are not picked up in sql case expressions

You need to specify what type of numeric you need e.g., numeric(10,2) so your code should start with (say)

    @inputUnits varchar(50),
    @unitInCase numeric(10,2),

See for info about numeric and decimal data types (which are synonymous). Broadly speaking, the first number represents the number of digits you wish to track (on both sides of the decimal point), whereas the second number is the number of digits after the decimal point.

See db<>fiddle with the code before and after.

In the example below, it shows what happens if you don’t set the scale and precision.

DECLARE @x numeric;
SET @x = 1.234567890;
-- Result is 1

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top