I have the following query
SELECT
f.SE_Factura,
SE_Consecutivo_Embarque,
f.SE_Orden_De_Compra,
f.SE_Orden_De_Venta,
f.SE_Fecha_OV,
f.SE_Cliente_Despachar_A,
(f.SE_Peso*e.SE_Cantidad_Embarcada)*400 as Peso,
(f.SE_Volumen*e.SE_Cantidad_Embarcada)*400 as Volumen
FROM SE_FactEmbarque f
INNER JOIN SE_Embarques e
ON e.SE_Orden_De_Venta = f.SE_Orden_De_Venta
AND (e.SE_Codigo_Articulo = f.SE_EAN_Articulo OR e.SE_Codigo_Articulo =
f.SE_Codigo_Articulo)
where f.SE_Factura = 'CD-40348'
which brings me the following data
Now what I am trying to do and I must do is to know which of the two is greater: the weight or the volume and multiply it by the rate in the following table
Where SE_Cliente_Despachar_A is equal to SE_Cliente
The use of the sentence
CASE
is very useful in these cases, I add the new column to your query, I hope it helps you.Using
CASE WHEN
you can solve your problem, that is, first validate ifPeso
is greater thanVolumen
and perform the operation: