如果列的值为0,则替换另一列SQLServer的值

时间:2017-12-04 14:44:58

标签: sql-server

如果列(cant_pallets_completo)的值为0,则替换另一列的值(cant_sku)

SELECT SUM(cant_pallets_completo) AS 'volumen_de_pallets' 
FROM estadistica_productividad_picking_rf 
WHERE cd='faseSQL' AND c_emp_user_grua <> '' ;

谢谢!

1 个答案:

答案 0 :(得分:1)

如果是SQL服务器,您可以尝试:

    SELECT SUM(CASE WHEN cant_pallets_completo = 0 
                    THEN cant_sku 
                    ELSE cant_pallets_completo END) AS 'volumen_de_pallets' 
    FROM estadistica_productividad_picking_rf 
    WHERE cd='faseSQL' AND c_emp_user_grua <> '' ;