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

    DELETE
      FROM IN_INTRAITEM
     WHERE SITEID    = @SITEID
       AND BATNBR    = @BATNBR
       AND TYPEDOCID = @TYPEDOCID
       AND SEQUENCE  = @SEQUENCE

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

    COMMIT TRAN

    RETURN(0)
END