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

GO

CREATE VIEW V_CAD_UNICO_DEPARAS_EST_PROD
AS
	SELECT DISTINCT
		B.CD_FILIAL,
		B.CD_BANDEIRA,
		D.CD_CTR_FK AS CD_PROD_BANDEIRA,
		D.CD_CTR_PK AS CD_PROD

	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 = 'EST_PROD' AND
		D.BANDEIRA = B.CD_BANDEIRA
		





