--
-- Definition for view RDX_V_STOCK_VARELA : 
--

CREATE VIEW RDX_V_STOCK_VARELA AS
SELECT ESTOQUE_PRODUTOS.FILIAL,
       ESTOQUE_PRODUTOS.PRODUTO AS CODIGO,
       ESTOQUE_PRODUTOS.COR_PRODUTO AS COLOR,
       PRODUCTO = PRODUTOS.DESC_PRODUTO,
       PRODUTOS.TIPO_PRODUTO,
       PRODUTOS.GRUPO_PRODUTO,
       COLECCION=COLECOES.DESC_COLECAO,

       ESTOQUE_PRODUTOS.ES1 as K38,
       ESTOQUE_PRODUTOS.ES2 as K40,
       ESTOQUE_PRODUTOS.ES3 as K42,
       ESTOQUE_PRODUTOS.ES4 as K44,
       ESTOQUE_PRODUTOS.ES5 as K46,
       ESTOQUE_PRODUTOS.ES6 as K48,
       ESTOQUE_PRODUTOS.ESTOQUE as KT

FROM ESTOQUE_PRODUTOS
LEFT OUTER JOIN PRODUTOS ON (PRODUTOS.PRODUTO = ESTOQUE_PRODUTOS.PRODUTO)
LEFT OUTER JOIN COLECOES ON (PRODUTOS.COLECAO = COLECOES.COLECAO)

WHERE FILIAL LIKE '%VARELA IMAGEN Y DISEŅO%'
GO



--
-- Definition for view RDX_V_STOCK_VENTAS : 
--

CREATE VIEW RDX_V_STOCK_VENTAS AS
SELECT
  PERVENINI AS FECHA,
  DAY(PERVENINI) AS DIA,
  DATENAME(DW, PERVENINI) DIASEMANA,
  DATENAME(MONTH, PERVENINI) AS MES,
  YEAR(PERVENINI) AS ANO,
  FILIAL AS CENTRO,
  CODIGO = ISNULL(PRODUTO, '107CH.EN.01'),
  DESC_PRODUTO AS PRODUCTO,
  GRUPO_PRODUTO AS GRUPOPRODUCTO,
  TIPO_PRODUTO AS TIPOPRODUCTO,
  DESC_COLECAO AS COLECCION,
  COLOR = ISNULL(COR_PRODUTO, '300'),
  GRADE AS TALLA,
  CANTIDAD = ISNULL(CANVEN, 0) + ISNULL(CANVENNET, 0)
FROM
  RDX_V_VENTASEDI_RESUELTAS
WHERE NOT ((DESC_PRODUTO LIKE '%ERROR REFERENCIA%') AND ((VALVEN < 1) AND (VALVEN > 0)))	/* QUITAR COMPOSTURAS */
GO


GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_V_STOCK_VENTAS]
TO [public]
GO


--
-- Definition for view RDX_V_STOCK_INVENTARIO : 
--

CREATE VIEW RDX_V_STOCK_INVENTARIO AS
SELECT
      FECHA = ISNULL(RDX_V_INVENTARIOEDI.FECHA, ISNULL(RDX_V_RECEPCION_AJUSTES_DESGLOSADO.FECHA, ISNULL(RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.FECHA, RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.FECHA))),
      CENTRO = ISNULL(RDX_V_INVENTARIOEDI.FILIAL, ISNULL(RDX_V_RECEPCION_AJUSTES_DESGLOSADO.FILIAL, ISNULL(RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.FILIAL, RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.FILIAL))),
      CODIGO = ISNULL(RDX_V_INVENTARIOEDI.CODIGO, ISNULL(RDX_V_RECEPCION_AJUSTES_DESGLOSADO.CODIGO, ISNULL(RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.CODIGO, RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.CODIGO))),
      PRODUCTO = ISNULL(RDX_V_INVENTARIOEDI.PRODUCTO, ISNULL(RDX_V_RECEPCION_AJUSTES_DESGLOSADO.PRODUCTO, ISNULL(RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.PRODUCTO, RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.PRODUCTO))),
      COLOR = ISNULL(RDX_V_INVENTARIOEDI.COLOR, ISNULL(RDX_V_RECEPCION_AJUSTES_DESGLOSADO.COLOR, ISNULL(RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.COLOR, RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.COLOR))),
      TALLA = ISNULL(RDX_V_INVENTARIOEDI.TALLA, ISNULL(RDX_V_RECEPCION_AJUSTES_DESGLOSADO.TALLA, ISNULL(RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.TALLA, RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.TALLA))),
      CANTIDAD = ISNULL(RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.CANTIDAD, ISNULL(RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.CANTIDAD, ISNULL(RDX_V_RECEPCION_AJUSTES_DESGLOSADO.CANTIDAD, RDX_V_INVENTARIOEDI.CANTIDAD))),
      /*RDX_V_INVENTARIOEDI.CANTIDAD,
      RDX_V_RECEPCION_AJUSTES_DESGLOSADO.CANTIDAD,
      RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.CANTIDAD,
      RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.CANTIDAD,*/
      OPERACION = CASE RDX_V_INVENTARIOEDI.TIPOCANT
                       WHEN '194' THEN 'R'
                       WHEN '46' THEN 'E'
                       WHEN '145' THEN 'RM'
                       WHEN '48' THEN 'S'
                       WHEN '61' THEN 'D'
                       WHEN '65' THEN 'T'
                       ELSE
                            CASE
                                WHEN RDX_V_RECEPCION_AJUSTES_DESGLOSADO.CANTIDAD IS NOT NULL THEN 'R'
                                WHEN RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.CANTIDAD IS NOT NULL THEN 'D'
                                ELSE RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.TIPO
                            END
                  END
FROM RDX_V_INVENTARIOEDI
FULL OUTER JOIN RDX_V_INVENTARIO_MAXFECHAS ON
     (RDX_V_INVENTARIO_MAXFECHAS.CENTRO = RDX_V_INVENTARIOEDI.CENTRO) AND
     (RDX_V_INVENTARIO_MAXFECHAS.CODIGO = RDX_V_INVENTARIOEDI.CODIGO) AND
     (RDX_V_INVENTARIO_MAXFECHAS.COLOR = RDX_V_INVENTARIOEDI.COLOR) AND
     (RDX_V_INVENTARIO_MAXFECHAS.TALLA = RDX_V_INVENTARIOEDI.TALLA)
FULL OUTER JOIN RDX_V_RECEPCION_AJUSTES_DESGLOSADO ON
     (RDX_V_RECEPCION_AJUSTES_DESGLOSADO.CENTRO = RDX_V_INVENTARIOEDI.CENTRO) AND
     (RDX_V_INVENTARIOEDI.CENTRO = RDX_V_INVENTARIOEDI.CENTRO2) AND
     (RDX_V_RECEPCION_AJUSTES_DESGLOSADO.CODIGO = RDX_V_INVENTARIOEDI.CODIGO) AND
     (RDX_V_RECEPCION_AJUSTES_DESGLOSADO.COLOR = RDX_V_INVENTARIOEDI.COLOR) AND
     (RDX_V_RECEPCION_AJUSTES_DESGLOSADO.TALLA = RDX_V_INVENTARIOEDI.TALLA) AND
     (RDX_V_RECEPCION_AJUSTES_DESGLOSADO.FECHA = RDX_V_INVENTARIOEDI.FECHA)
FULL OUTER JOIN RDX_V_TRASPASOS_AJUSTES_DESGLOSADO ON
     (RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.CENTRO = RDX_V_INVENTARIOEDI.CENTRO) AND
     (RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.CENTRO2 = RDX_V_INVENTARIOEDI.CENTRO2) AND
     (RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.CODIGO = RDX_V_INVENTARIOEDI.CODIGO) AND
     (RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.COLOR = RDX_V_INVENTARIOEDI.COLOR) AND
     (RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.TALLA = RDX_V_INVENTARIOEDI.TALLA) AND
     (RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.FECHA = RDX_V_INVENTARIOEDI.FECHA) AND
     (RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.TIPO = RDX_V_INVENTARIOEDI.TIPOCANT)
FULL OUTER JOIN RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO ON
     (RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.CENTRO = RDX_V_INVENTARIOEDI.CENTRO) AND
     (RDX_V_INVENTARIOEDI.CENTRO = RDX_V_INVENTARIOEDI.CENTRO2) AND
     (RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.CODIGO = RDX_V_INVENTARIOEDI.CODIGO) AND
     (RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.COLOR = RDX_V_INVENTARIOEDI.COLOR) AND
     (RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.TALLA = RDX_V_INVENTARIOEDI.TALLA) AND
     (RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.FECHA = RDX_V_INVENTARIOEDI.FECHA)
WHERE
     ((RDX_V_INVENTARIO_MAXFECHAS.FECHA IS NULL)  /* Puede haber prendas que no se hayan inventariado nunca */
     OR
      (ISNULL(RDX_V_INVENTARIOEDI.FECHA, ISNULL(RDX_V_RECEPCION_AJUSTES_DESGLOSADO.FECHA, ISNULL(RDX_V_TRASPASOS_AJUSTES_DESGLOSADO.FECHA, RDX_V_DEVOLUCION_AJUSTES_DESGLOSADO.FECHA))) >= RDX_V_INVENTARIO_MAXFECHAS.FECHA))
GO

GRANT SELECT, INSERT, DELETE, REFERENCES, UPDATE
ON [RDX_V_STOCK_INVENTARIO]
TO [public]
GO


--
-- Definition for view RDX_V_STOCK : 
--

CREATE VIEW RDX_V_STOCK AS
SELECT
      CENTRO = ISNULL(RDX_V_STOCK_INVENTARIO.CENTRO, RDX_V_STOCK_VENTAS.CENTRO),
      CODIGO = ISNULL(RDX_V_STOCK_INVENTARIO.CODIGO, RDX_V_STOCK_VENTAS.CODIGO),
      PRODUCTO = ISNULL(RDX_V_STOCK_INVENTARIO.PRODUCTO, RDX_V_STOCK_VENTAS.PRODUCTO),
      TIPO_PRODUCTO = PRODUTOS.TIPO_PRODUTO,
      GRUPO_PRODUCTO = PRODUTOS.GRUPO_PRODUTO,
      COLECCION = COLECOES.DESC_COLECAO,
      COLOR = ISNULL(RDX_V_STOCK_INVENTARIO.COLOR, RDX_V_STOCK_VENTAS.COLOR),
      E38 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '38' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'RM' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'R' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'E' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) > 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      E40 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '40' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'RM' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'R' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'E' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) > 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      E42 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '42' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'RM' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'R' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'E' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) > 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      E44 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '44' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'RM' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'R' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'E' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) > 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      E46 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '46' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'RM' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'R' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'E' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) > 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      E48 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '48' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'RM' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'R' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           WHEN 'E' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) > 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      S38 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '38' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'D' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'S' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'T' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) < 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      S40 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '40' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'D' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'S' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'T' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) < 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      S42 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '42' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'D' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'S' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'T' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) < 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      S44 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '44' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'D' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'S' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'T' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) < 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      S46 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '46' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'D' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'S' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'T' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) < 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END),

      S48 = SUM(CASE ISNULL(RDX_V_STOCK_INVENTARIO.TALLA, RDX_V_STOCK_VENTAS.TALLA)
                 WHEN '48' THEN
                      CASE RDX_V_STOCK_INVENTARIO.OPERACION
                           WHEN 'D' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'S' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           WHEN 'T' THEN RDX_V_STOCK_INVENTARIO.CANTIDAD * (-1)
                           ELSE
                               0
                      END
                      +
                      CASE
                          WHEN ((RDX_V_STOCK_VENTAS.CANTIDAD * (-1)) < 0) THEN
                              RDX_V_STOCK_VENTAS.CANTIDAD * (-1)
                          ELSE
                              0
                      END
                 END)
FROM
  RDX_V_STOCK_INVENTARIO
FULL OUTER JOIN RDX_V_STOCK_VENTAS ON
     (RDX_V_STOCK_INVENTARIO.CENTRO = RDX_V_STOCK_VENTAS.CENTRO)
     AND (RDX_V_STOCK_INVENTARIO.CODIGO = RDX_V_STOCK_VENTAS.CODIGO)
     AND (RDX_V_STOCK_INVENTARIO.COLOR = RDX_V_STOCK_VENTAS.COLOR)
     AND (RDX_V_STOCK_INVENTARIO.TALLA = RDX_V_STOCK_VENTAS.TALLA)
     AND (RDX_V_STOCK_INVENTARIO.FECHA = RDX_V_STOCK_VENTAS.FECHA)
LEFT OUTER JOIN PRODUTOS ON
     (PRODUTOS.PRODUTO = ISNULL(RDX_V_STOCK_INVENTARIO.CODIGO, RDX_V_STOCK_VENTAS.CODIGO))
LEFT OUTER JOIN COLECOES ON
     (COLECOES.COLECAO = PRODUTOS.COLECAO)

GROUP BY
      ISNULL(RDX_V_STOCK_INVENTARIO.CENTRO, RDX_V_STOCK_VENTAS.CENTRO),
      ISNULL(RDX_V_STOCK_INVENTARIO.CODIGO, RDX_V_STOCK_VENTAS.CODIGO),
      ISNULL(RDX_V_STOCK_INVENTARIO.PRODUCTO, RDX_V_STOCK_VENTAS.PRODUCTO),
      PRODUTOS.TIPO_PRODUTO,
      PRODUTOS.GRUPO_PRODUTO,
      COLECOES.DESC_COLECAO,
      ISNULL(RDX_V_STOCK_INVENTARIO.COLOR, RDX_V_STOCK_VENTAS.COLOR)
GO

--
-- Definition for view RDX_V_STOCK_CALCULADO : 
--

CREATE VIEW RDX_V_STOCK_CALCULADO AS
SELECT
      CENTRO,
      CODIGO,
      PRODUCTO,
      TIPO_PRODUCTO,
      GRUPO_PRODUCTO,
      COLECCION,
      COLOR,
      E38,
      E40,
      E42,
      E44,
      E46,
      E48,
      TE = ISNULL(E38, 0) + ISNULL(E40, 0) + ISNULL(E42, 0) + ISNULL(E44, 0) + ISNULL(E46, 0) + ISNULL(E48, 0),
      S38,
      S40,
      S42,
      S44,
      S46,
      S48,
      TS = ISNULL(S38, 0) + ISNULL(S40, 0) + ISNULL(S42, 0) + ISNULL(S44, 0) + ISNULL(S46, 0) + ISNULL(S48, 0),
      K38 = ISNULL(E38, 0) + ISNULL(S38, 0),
      K40 = ISNULL(E40, 0) + ISNULL(S40, 0),
      K42 = ISNULL(E42, 0) + ISNULL(S42, 0),
      K44 = ISNULL(E44, 0) + ISNULL(S44, 0),
      K46 = ISNULL(E46, 0) + ISNULL(S46, 0),
      K48 = ISNULL(E48, 0) + ISNULL(S48, 0),
      KT = ISNULL(E38, 0) + ISNULL(S38, 0) + ISNULL(E40, 0) + ISNULL(S40, 0) +
           ISNULL(E42, 0) + ISNULL(S42, 0) + ISNULL(E44, 0) + ISNULL(S44, 0) +
           ISNULL(E46, 0) + ISNULL(S46, 0) + ISNULL(E48, 0) + ISNULL(S48, 0)

FROM RDX_V_STOCK
GO








