Código SQL:
Ver originalSELECT
"SDLITM" AS "Codigo1",
"SDAITM" AS "Codigo2",
"SDDSC1" AS "Producto",
"SDMCU" AS "Bodega",
"DRDL01" AS "N_Vendedor",
SUM(sdsoqs) AS "Cantidad",
SUM(sduprc) AS "PrecioU",
SUM(SDAEXP) AS "Valor",
SUM(sduncs) AS "CostoU",
SUM(sdecst) AS "Costo",
"IMALN" AS "IMALN",
"IMSRP1" AS "IMSRP1",
"IMSRP2" AS "Clasificacion2",
"IMSRP3" AS "Clasificacion3",
"IMSRP4" AS "Clasificacion4",
"IMSRP5" AS "Clasificacion5",
"IMSRP6" AS "Clasificacion6",
"IMSRP7" AS "Clasificacion7",
"IMSRP8" AS "Marca",
"IMSRP0" AS "Presentacion",
--"SDDOC" as "DOCUMENTO",
"SDDCT" AS "TIPO",
"SDUOM" AS "Unidad",
"SDCRCD" AS "Moneda",
SUM("SDAEXP"/100-"SDECST"/100) AS "UTILIDAD_B",
CASE
WHEN "SDECST" = 0 THEN 0
ELSE (SUM("SDAEXP"/100)/SUM("SDECST"/100) -1)*100
END "MARGEN",
"ABAN8" AS "ABAN8",
"ABALPH" AS "Cliente",
"ABAC09" AS "C_Vendedor",
"MCRP22" AS "Establecimiento"
FROM PRUEBAVENTAS
GROUP BY "SDDSC1",
"SDLITM",
"SDAITM",
"SDDSC1",
"SDMCU",
"DRDL01",
"IMALN",
"IMSRP1",
"IMSRP2",
"IMSRP3",
"IMSRP4",
"IMSRP5",
"IMSRP6",
"IMSRP7",
"IMSRP8",
"IMSRP0",
-- "SDDOC",
"SDDCT",
"SDUOM",
"SDCRCD",
--"SDECST",
"ABAN8",
"ABALPH",
"ABAC09",
"MCRP22"
El inconveniente está en esta seccion de codigo:
Código SQL:
Ver originalCASE
WHEN "SDECST" = 0 THEN 0
ELSE (SUM("F42119"."SDAEXP"/100)/SUM("F42119"."SDECST"/100) -1)*100
END "MARGEN",
En el WHEN, cuando COSTO (SDECST) sea igual a 0 debo mostrar 0, ahí es donde aparece el problema al no estar aplicando ninguna funcion de agrupacion debo incluir
SDECST en el GROUP y al tener este valores diferentes no me agrupa los productos.
Como puedo hacer el WHEN "SDECST" = 0 THEN 0 si necesidad de incluir "SDECST en el GROUP BY?, ya que esto daña mi consulta.
http://squadronsuicida.webs.com/imag...-%20copia.xlsx