IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[P_EST_PROD_TRIB_DROGASMIL]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[P_EST_PROD_TRIB_DROGASMIL]
GO

CREATE PROCEDURE [dbo].[P_EST_PROD_TRIB_DROGASMIL] (@CD_FILIAL INT, @TP_MOV INT, @TP_TRANSA INT, @CD_PROD INT = 0)
AS BEGIN
SELECT DISTINCT
V.CD_TRIB_VD AS CD_TRIB,
ISNULL(T.CD_TRIB_FC,'000') AS CD_TRIB_FC,
V.PERC_ICMS_N_CONT_ESTA  AS PERC_ICMS,
0 AS ModDetBC,
V.PERC_RED_VD AS PERC_RED
FROM	V_EST_PROD_CPL_PDV V
INNER JOIN EST_TRIB T
ON T.CD_TRIB = V.CD_TRIB_VD
WHERE 
V.CD_FILIAL = @CD_FILIAL

END

