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

CREATE PROCEDURE dbo.P_VINCULAR_EST_PROD_FORN
(
    @CD_EMP   INT,
    @CD_PROD  INT,
    @CD_FORN  INT,
    @CD_USU   INT
)
AS
BEGIN
    SET NOCOUNT ON;

    IF NOT EXISTS (
        SELECT 1
        FROM EST_PROD_FORN
        WHERE CD_EMP  = @CD_EMP
          AND CD_PROD = @CD_PROD
          AND CD_FORN = @CD_FORN
    )
    BEGIN
        INSERT INTO EST_PROD_FORN
        (
            CD_EMP,
            CD_PROD,
            CD_FORN,
            CD_PROD_FORN,
            COMPRA_INATIVA,
            CD_USU,
            COMPRA_OL,
            COMPRA_COT,
            APRES_EMB_CP,
            APRES_QT_CP_OLD,
            DT_ULT_ALT,
            FLAG_TIPO_CONVERSAO,
            APRES_QT_CP
        )
        VALUES
        (
            @CD_EMP,
            @CD_PROD,
            @CD_FORN,
            '',
            0,
            @CD_USU,
            0,
            0,
            1,
            1,
            GETDATE(),
            0,
            1
        );
    END
END;
GO