
IF OBJECT_ID('V_CAD_UNICO_DEPARAS_PRC_FILIAL') IS NOT NULL
BEGIN
	DROP VIEW V_CAD_UNICO_DEPARAS_PRC_FILIAL
END

GO

CREATE VIEW V_CAD_UNICO_DEPARAS_PRC_FILIAL
AS
	SELECT 
		F.CD_FILIAL,
		B.CD_BANDEIRA,
		D.CD_CTR_FK AS CD_FILIAL_BANDEIRA,
		B.FLAG_CONTROLE_DEPARA
	FROM 
		PRC_FILIAL F
		INNER JOIN PRC_BANDEIRA_PRC_FILIAL B
		ON F.CD_EMP = B.CD_EMP AND F.CD_FILIAL = B.CD_FILIAL
		INNER JOIN CAD_UNICO_DEPARAS D
		ON D.TABELA = 'PRC_FILIAL' AND F.CD_FILIAL = D.CD_CTR_PK


