
IF NOT EXISTS (
    SELECT 1 
    FROM sys.objects 
    WHERE object_id = OBJECT_ID('dbo.EST_RPS_IT_IBS_CBS') 
      AND type = 'U'
)
BEGIN
    CREATE TABLE dbo.EST_RPS_IT_IBS_CBS (
        id  INT NOT NULL,
		num_rps  INT NOT NULL,
		cd_filial  INT NOT NULL,
		cd_emp  INT NOT NULL,
		finNFSe INT not NULL,
		indFinal INT not NULL,
		cIndOp VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CI_AS,
		cst VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CI_AS,
		cClassTrib VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CI_AS,
		cCredPres VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CI_AS,
		cstReg VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CI_AS,
		cClassTribReg VARCHAR(10) COLLATE SQL_Latin1_General_CP1_CI_AS,
		pDifUf MONEY not null default 0,
		pDifMun MONEY not null default 0,
		pDifCbs MONEY not null default 0,
		tpOper INT not NULL,
		refNFSe VARCHAR(100) COLLATE SQL_Latin1_General_CP1_CI_AS,
		tpEnteGov INT not NULL,
		cLocalidadeIncid VARCHAR(7) COLLATE SQL_Latin1_General_CP1_CI_AS,
		xLocalidadeIncid VARCHAR(600) COLLATE SQL_Latin1_General_CP1_CI_AS,
		vBc MONEY not null default 0,
		vCalcReeRepRes MONEY not null default 0,
		pIbsUf MONEY not null default 0,
		pRedAliqUf MONEY not null default 0,
		pAliqEfetUf MONEY not null default 0,
		pIbsMun MONEY not null default 0,
		pRedAliqMun MONEY not null default 0,
		pAliqEfetMun MONEY not null default 0,
		pCbs MONEY not null default 0,
		pRedAliqCbs MONEY not null default 0,
		pAliqEfetCbs MONEY not null default 0,	
		vTotNF MONEY not null default 0,
		tot_pAliqEfeRegIbsUf MONEY not null default 0,
		tot_vTribRegIbsUf MONEY not null default 0,
		tot_pAliqEfeRegIbsMun MONEY not null default 0,
		tot_vTribRegIbsMun MONEY not null default 0,
		tot_pAliqEfeRegCbs MONEY not null default 0,
		tot_vTribRegCbs MONEY not null default 0,
		tot_pIbsUf MONEY not null default 0,
		tot_vIbsUf MONEY not null default 0,
		tot_pIbsMun MONEY not null default 0,
		tot_vIbsMun MONEY not null default 0,
		tot_pCbs MONEY not null default 0,
		tot_vCbs MONEY not null default 0,
		tot_vIbsTot MONEY not null default 0,
		tot_pCredPresIbs MONEY not null default 0,
		tot_vCredPresIbs MONEY not null default 0,
		tot_vDifUf MONEY not null default 0,
		tot_vDifMun MONEY not null default 0,
        CONSTRAINT PK_EST_RPS_IT_IBS_CBS PRIMARY KEY (id, num_rps, cd_filial, cd_emp)
    );
END;
GO


