DROP PROCEDURE IN_INTRAHEADDelProc
GO
CREATE PROCEDURE IN_INTRAHEADDelProc
(
    @SITEID            UD_IDSITE,
    @BATNBR            char(10),
    @TYPEDOCID         UD_TYPEMOVEID)
AS
BEGIN
    BEGIN TRAN

    DELETE
      FROM IN_INTRAHEAD
     WHERE SITEID    = @SITEID
       AND BATNBR    = @BATNBR
       AND TYPEDOCID = @TYPEDOCID

    IF (@@error!=0)
    BEGIN
        RAISERROR  20002 'IN_INTRAHEADDelProc: Cannot delete because foreign keys still exist in IN_INTRAHEAD '
        ROLLBACK TRAN
        RETURN(1)
    
    END

    COMMIT TRAN

    RETURN(0)
END