IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='GLB_TP_FIDEL_LINXPROMO') 
BEGIN
 
    CREATE TABLE  GLB_TP_FIDEL_LINXPROMO (
	    CD_EMP 				INT  NOT NULL,
	    CD_FILIAL 			INT  NOT NULL,
		CD_CTR 				INT  NOT NULL,
	    CD_TP_CARTAO 		VARCHAR(MAX)COLLATE SQL_LATIN1_GENERAL_CP1_CI_AS NULL,
		DS_TP_CARTAO 		VARCHAR(40) COLLATE SQL_LATIN1_GENERAL_CP1_CI_AS NULL,
		PREFIXO_TP_CARTAO	VARCHAR(40) COLLATE SQL_LATIN1_GENERAL_CP1_CI_AS NULL,
		STS_TP_CARTAO 		INT  NOT NULL
	CONSTRAINT PK_GLB_TP_FIDEL_LINXPROMO  PRIMARY KEY CLUSTERED (CD_EMP ,CD_CTR  ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 
	) 
END

go

IF NOT EXISTS (SELECT TOP 1 *  FROM GLB_TP_FIDEL_LINXPROMO WHERE DS_TP_CARTAO = 'NÃO DEFINIDO' OR (CD_EMP = (SELECT MIN(CD_EMP) FROM PRC_FILIAL) AND CD_CTR = 0) )
BEGIN 
	INSERT INTO GLB_TP_FIDEL_LINXPROMO(CD_EMP, CD_FILIAL, CD_CTR, CD_TP_CARTAO, DS_TP_CARTAO, PREFIXO_TP_CARTAO, STS_TP_CARTAO)
	VALUES ((SELECT MIN(CD_EMP) FROM PRC_FILIAL),(SELECT MIN(CD_FILIAL) FROM PRC_FILIAL),0,'NÃO DEFINIDO','NÃO DEFINIDO','NÃO DEFINIDO',0)
END 