IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[PRC_WSCONCILIADOR_LINX]') AND TYPE IN (N'U'))
BEGIN
CREATE TABLE DBO.PRC_WSCONCILIADOR_LINX (
	CD_EMP			INT CONSTRAINT DF_PRC_WSCONCILIADOR_LINX_CD_EMP DEFAULT 0 NOT NULL,
	CD_FILIAL		INT CONSTRAINT DF_PRC_WSCONCILIADOR_LINX_CD_FILIAL DEFAULT 0 NOT NULL,
	DT_INICIO_VENDA DATE NULL,
	DT_FINAL_VENDA	DATE NULL,
	DT_INICIO_PGTO	DATE NULL,
	DT_FINAL_PGTO	DATE NULL,
	DT_INICIO_ALT	DATE NULL,
	DT_FINAL_ALT	DATE NULL,
	CONSTRAINT PK_PRC_WSCONCILIADOR_LINX PRIMARY KEY (CD_EMP,CD_FILIAL),
	CONSTRAINT FK_PRC_WSCONC_LINX_EMP_PRC_EMP FOREIGN KEY (CD_EMP) REFERENCES PRC_EMP(CD_EMP),
	CONSTRAINT FK_PRC_WSCONC_LINX_FILIAL_PRC_FILIAL FOREIGN KEY (CD_EMP,CD_FILIAL) REFERENCES PRC_FILIAL(CD_EMP,CD_FILIAL)
) 
END
IF NOT EXISTS (SELECT TOP 1 * FROM PRC_WSCONCILIADOR_LINX)
BEGIN 
	DROP TABLE PRC_WSCONCILIADOR_LINX

CREATE TABLE DBO.PRC_WSCONCILIADOR_LINX (
	CD_EMP			INT CONSTRAINT DF_PRC_WSCONCILIADOR_LINX_CD_EMP DEFAULT 0 NOT NULL,
	CD_FILIAL		INT CONSTRAINT DF_PRC_WSCONCILIADOR_LINX_CD_FILIAL DEFAULT 0 NOT NULL,
	DT_INICIO_VENDA DATE NULL,
	DT_FINAL_VENDA	DATE NULL,
	DT_INICIO_PGTO	DATE NULL,
	DT_FINAL_PGTO	DATE NULL,
	DT_INICIO_ALT	DATE NULL,
	DT_FINAL_ALT	DATE NULL,
	CONSTRAINT PK_PRC_WSCONCILIADOR_LINX PRIMARY KEY (CD_EMP,CD_FILIAL),
	CONSTRAINT FK_PRC_WSCONC_LINX_EMP_PRC_EMP FOREIGN KEY (CD_EMP) REFERENCES PRC_EMP(CD_EMP),
	CONSTRAINT FK_PRC_WSCONC_LINX_FILIAL_PRC_FILIAL FOREIGN KEY (CD_EMP,CD_FILIAL) REFERENCES PRC_FILIAL(CD_EMP,CD_FILIAL)
) 
END