How to get this in decimal value instead of null

后端 未结 4 1945
萌比男神i
萌比男神i 2021-01-29 10:13

i am trying to get value in Decimal in this query but unable to get i am getting NULL Value

SELECT CAST(CAST(CAST(SUM(CAST(0 AS INT)) AS DECIMAL(10, 2)) * 100 
         


        
4条回答
  •  面向向阳花
    2021-01-29 10:45

    Way too many CASTs in that SQL

    Use a CASE if you don't want to use ISNULL, which is needed because you have NULLIF

    SELECT 
      CAST(
        CASE
          WHEN SUM(CAST(0 AS INT)) + SUM(CAST(0 AS INT)) + SUM(CAST(0 AS INT)) = 0 THEN 0
          ELSE SUM(CAST(0 AS INT)) * 100.00 / (SUM(CAST(0 AS INT)) + SUM(CAST(0 AS INT)) + SUM(CAST(0 AS INT)))
      END
      AS DECIMAL(10, 2))
    

    Howver, anything divided by zero is undefined or infinity: not zero.

提交回复
热议问题