CREATE NONCLUSTERED INDEX [RDX_REFERENCIA_GENERICA_idx3] ON [dbo].[RDX_REFERENCIA_GENERICA]
  ([ESTADO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_FILIALES_idx] ON [dbo].[RDX_FILIALES]
  ([CODBARRA])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO


CREATE NONCLUSTERED INDEX [RDX_FILIALES_idx2] ON [dbo].[RDX_FILIALES]
  ([CODFILIAL])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [FILIAIS_idx] ON [dbo].[FILIAIS]
  ([COD_FILIAL])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [LOJA_VENDEDORES_idx] ON [dbo].[LOJA_VENDEDORES]
  ([RG])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_CANTINV_idx3] ON [dbo].[RDX_CANTINV]
  ([TIPOCANT])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO


CREATE NONCLUSTERED INDEX [RDX_AJUSTES_ALBARAN_idx] ON [dbo].[RDX_AJUSTES_ALBARAN]
  ([ESTADO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_AJUSTES_ALBARAN_idx2] ON [dbo].[RDX_AJUSTES_ALBARAN]
  ([CONTABILIZAR])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [FATURAMENTO_TIPO_idx] ON [dbo].[FATURAMENTO_TIPO]
  ([INDICADOR_TIPO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_TALLAS_idx] ON [dbo].[RDX_TALLAS]
  ([TALLA])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO


CREATE NONCLUSTERED INDEX [RDX_TRASPASOS_AJUSTES_idx] ON [dbo].[RDX_TRASPASOS_AJUSTES]
  ([APROBADO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_TRASPASOS_AJUSTES_idx2] ON [dbo].[RDX_TRASPASOS_AJUSTES]
  ([ESTADO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO


CREATE NONCLUSTERED INDEX [RDX_DEVOLUCION_AJUSTES_idx] ON [dbo].[RDX_DEVOLUCION_AJUSTES]
  ([APROBADO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_DEVOLUCION_AJUSTES_idx2] ON [dbo].[RDX_DEVOLUCION_AJUSTES]
  ([FECHACAMBIO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [PRODUTOS_idx] ON [dbo].[PRODUTOS]
  ([DESC_PRODUTO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_ARTVEN_idx] ON [dbo].[RDX_ARTVEN]
  ([EANART])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_ARTVEN_idx2] ON [dbo].[RDX_ARTVEN]
  ([CODCOM])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_ARTVEN_idx4] ON [dbo].[RDX_ARTVEN]
  ([NUMTALON])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_ARTVEN_idx5] ON [dbo].[RDX_ARTVEN]
  ([EANVEN])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_CABVEN_idx] ON [dbo].[RDX_CABVEN]
  ([NUMINF])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_CABVEN_idx2] ON [dbo].[RDX_CABVEN]
  ([IGNORAR])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_INFORMES_idx] ON [dbo].[RDX_INFORMES]
  ([CATEGORIA])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_LUGVEN_idx] ON [dbo].[RDX_LUGVEN]
  ([EANLUG])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_RECEPCION_AJUSTES_idx] ON [dbo].[RDX_RECEPCION_AJUSTES]
  ([FECHACAMBIO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_RECEPCION_AJUSTES_idx2] ON [dbo].[RDX_RECEPCION_AJUSTES]
  ([APROBADO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [RDX_REFERENCIA_GENERICA_idx] ON [dbo].[RDX_REFERENCIA_GENERICA]
  ([FECHACAMBIO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_REFERENCIA_GENERICA_idx2] ON [dbo].[RDX_REFERENCIA_GENERICA]
  ([CODIGO_BARRA])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
GO

CREATE NONCLUSTERED INDEX [RDX_TRASPASOS_AJUSTES_idx3] ON [dbo].[RDX_TRASPASOS_AJUSTES]
  ([FECHACAMBIO])
WITH (
  PAD_INDEX = OFF,
  DROP_EXISTING = OFF,
  STATISTICS_NORECOMPUTE = OFF,
  SORT_IN_TEMPDB = OFF,
  ONLINE = OFF,
  ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
GO














CREATE VIEW RDX_V_INVENTARIOEDI AS
SELECT
      RDX_CANTINV.NUMDOC,
      RDX_CANTINV.NUMLIN,
      RDX_CANTINV.NUMCANT,
      RDX_CANTINV.TIPOCANT,
      RDX_CABINV.FECHALIQ AS FECHA,
      RDX_CABINV.CENTRO,
      FILIAL = ISNULL(FILIAIS.FILIAL, RDX_CABINV.CENTRO),
      RDX_CANTINV.IDVEN AS CODVEN,
      VENDEDOR = ISNULL(LTRIM(RTRIM(LOJA_VENDEDORES.NOME_VENDEDOR)) + ' ' + LTRIM(RTRIM(LOJA_VENDEDORES.VENDEDOR_APELIDO)), RDX_CANTINV.IDVEN),
      RDX_LININV.CODART AS CODIGO_BARRA,
      CODIGO = ISNULL(PRODUTOS.PRODUTO, '107CH.EN.01'),
      PRODUCTO = ISNULL(PRODUTOS.DESC_PRODUTO, '*** ERROR REFERENCIA  **** LLAMAR AL CI'),
      COLOR = ISNULL(PRODUTOS_BARRA.COR_PRODUTO, 300),
      TALLA = PRODUTOS_BARRA.GRADE,
      RDX_CANTINV.CANTIDAD,
      CENTRO2 = RDX_CANTINV.CENTRO,
      FILIAL2 = ISNULL(FILIAIS2.FILIAL, RDX_CANTINV.CENTRO)
FROM RDX_CANTINV
INNER JOIN RDX_LININV ON
      ((RDX_LININV.NUMDOC = RDX_CANTINV.NUMDOC) AND
       (RDX_LININV.NUMLIN = RDX_CANTINV.NUMLIN))
INNER JOIN RDX_CABINV ON
      (RDX_CABINV.NUMDOC = RDX_LININV.NUMDOC)
LEFT OUTER JOIN RDX_FILIALES ON (RDX_FILIALES.CODBARRA = RDX_CABINV.CENTRO)
LEFT OUTER JOIN FILIAIS ON (FILIAIS.COD_FILIAL = RDX_FILIALES.CODFILIAL)
LEFT OUTER JOIN RDX_FILIALES RDX_FILIALES2 ON (RDX_FILIALES2.CODBARRA = RDX_CANTINV.CENTRO)
LEFT OUTER JOIN FILIAIS FILIAIS2 ON (FILIAIS2.COD_FILIAL = RDX_FILIALES2.CODFILIAL)
LEFT OUTER JOIN LOJA_VENDEDORES ON (LOJA_VENDEDORES.RG = RDX_CANTINV.IDVEN)
LEFT OUTER JOIN PRODUTOS_BARRA ON ((PRODUTOS_BARRA.CODIGO_BARRA = RDX_LININV.CODART))
LEFT OUTER JOIN PRODUTOS ON (PRODUTOS.PRODUTO = PRODUTOS_BARRA.PRODUTO)
WHERE RDX_CABINV.FECHALIQ >= convert(datetime, '20060601', 112)  /* PARA NO COGER AŅOS ANTERIORES */
AND (RDX_CABINV.IGNORAR IS NULL) OR (RDX_CABINV.IGNORAR <> 'S')
GO



create table RDX_INVENTARIOEDI (
  [NUMDOC]numeric(10, 0) NOT NULL,
  [NUMLIN]numeric(5, 0) NOT NULL,
  [NUMCANT]varchar(17) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [TIPOCANT]varchar(70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [FECHA]datetime NULL,
  [CENTRO]datetime NULL,
  [FILIAL]datetime NULL,
  [CODVEN]datetime NULL,
  [VENDEDOR]datetime NULL,
  [CODIGO_BARRA]
  [CODIGO]
  [PRODUCTO]
  [COLOR]
  [TALLA]
  [CANTIDAD]
  [CENTRO2]
  [FILIAL2]
  PRIMARY KEY CLUSTERED ([CLAVE1], [CLAVE2]),
  CONSTRAINT [FK__RDX_LUGVE__CLAVE__4A59F0B5] FOREIGN KEY ([CLAVE1]) 
  REFERENCES [dbo].[RDX_CABVEN] ([CLAVE1]) 
  ON UPDATE CASCADE
  ON DELETE CASCADE
)

















