IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RC_ADM_CARTAO_EQUALSCORE_BANDEIRA]') AND type in (N'U'))
BEGIN


INSERT INTO RC_ADM_CARTAO_EQUALSCORE_BANDEIRA
SELECT CD_BANDEIRA, CD_ADM_CARTAO
  FROM RC_ADM_CARTAO
       INNER JOIN EQUALSCORE_BANDEIRA ON RC_ADM_CARTAO.NM_USUAL LIKE CONCAT('%', EQUALSCORE_BANDEIRA.DS_BANDEIRA, '%') AND CD_ADM_CARTAO NOT IN (SELECT CD_ADM_CARTAO  FROM RC_ADM_CARTAO_EQUALSCORE_BANDEIRA);

-- DINNERS CLUB
INSERT INTO RC_ADM_CARTAO_EQUALSCORE_BANDEIRA
SELECT 4, CD_ADM_CARTAO
  FROM RC_ADM_CARTAO
 WHERE RC_ADM_CARTAO.NM_USUAL LIKE ('%DINERS%') AND CD_ADM_CARTAO NOT IN (SELECT CD_ADM_CARTAO  FROM RC_ADM_CARTAO_EQUALSCORE_BANDEIRA)

-- CREDISYSTEM
INSERT INTO RC_ADM_CARTAO_EQUALSCORE_BANDEIRA
SELECT 12, CD_ADM_CARTAO
  FROM RC_ADM_CARTAO
 WHERE RC_ADM_CARTAO.NM_USUAL LIKE ('%CREDISYSTEM%') AND CD_ADM_CARTAO NOT IN (SELECT CD_ADM_CARTAO  FROM RC_ADM_CARTAO_EQUALSCORE_BANDEIRA)

-- JCB
INSERT INTO RC_ADM_CARTAO_EQUALSCORE_BANDEIRA
SELECT 31, CD_ADM_CARTAO
  FROM RC_ADM_CARTAO
 WHERE RC_ADM_CARTAO.NM_USUAL LIKE ('%JBC%') AND CD_ADM_CARTAO NOT IN (SELECT CD_ADM_CARTAO  FROM RC_ADM_CARTAO_EQUALSCORE_BANDEIRA)


-- SOROCRED
INSERT INTO RC_ADM_CARTAO_EQUALSCORE_BANDEIRA
SELECT 11, CD_ADM_CARTAO
  FROM RC_ADM_CARTAO
 WHERE RC_ADM_CARTAO.NM_USUAL LIKE ('%SORO%') AND CD_ADM_CARTAO NOT IN (SELECT CD_ADM_CARTAO  FROM RC_ADM_CARTAO_EQUALSCORE_BANDEIRA)

-- LINX
INSERT INTO RC_ADM_CARTAO_EQUALSCORE_BANDEIRA
SELECT 144, CD_ADM_CARTAO
  FROM RC_ADM_CARTAO
 WHERE RC_ADM_CARTAO.NM_USUAL LIKE ('%LINX%') AND CD_ADM_CARTAO NOT IN (SELECT CD_ADM_CARTAO  FROM RC_ADM_CARTAO_EQUALSCORE_BANDEIRA)

END