DROP PROC OP_GRABAR_TMPOPSALESCARD
GO

CREATE PROC OP_GRABAR_TMPOPSALESCARD
(
    @corrnbr         int,
    @SITEID	     UD_IDSITE,
    @CARDID          char(2),
    @NBRCARD         char(20),
    @curyid	     ud_curyid,
    @TOTCARDPEN      UD_MONTO,
    @TOTCARDUSD      UD_MONTO )
AS
BEGIN
declare    @SEQUENCE        UD_REGISTRO

set  @SEQUENCE =(SELECT COUNT(*)+1 FROM tmp_OP_SALESCARD WHERE corrnbr=@corrnbr)
    BEGIN TRAN

    INSERT INTO tmp_OP_SALESCARD(corrnbr,
			     SITEID,
                             SEQUENCE,
                             CARDID,
                             NBRCARD,
			     curyid,
                             TOTCARDPEN,
                             TOTCARDUSD)
    VALUES(@corrnbr,
	   @SITEID,
           @SEQUENCE,
           @CARDID,
           @NBRCARD,
	   @curyid,
           @TOTCARDPEN,
           @TOTCARDUSD )

    IF (@@error!=0)
    BEGIN
        RAISERROR  20000 'SP_InsProcOP_SALESCARD: Cannot insert because primary key value not found in OP_SALESCARD '
        ROLLBACK TRAN
        RETURN(1)

    END
    COMMIT TRAN

END
GO
