cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger to judge whether the input data from A total is greater than the B table

ximen
Participant
0 Kudos
2,297

A table: TRANS_No part_id quantity unit_price ar_amt customer_id

         TR001       A001    10        30          300      Customer001

         TR001       A004    20        40          800      customer001

  B tabel:

          customer_id     limit

          customer001       900
insert A if
 sum(a.ar_amt)>b.limit      --Are not allowed to insert data
 sum(a.ar_amt)<b.limit      --can insertdata)

How to use the trigger judge whether the insert data of A total is greater than the table B, if the limit is greater than B is not allowed to insert So what do I need the triggers. If he is greater than the number that I will let him save, the judgment of statements or constraint statement I should how to write?

Accepted Solutions (1)

Accepted Solutions (1)

ximen
Participant
0 Kudos

Thanks for jason.hinsperger help me : The answer is:

 Declare tot integer;

    Declare lim integer;

    Select sum(amt) into tot where customer_id = newrow.customer_id;

    Select limit into lim where customer_id = newrow.customer_id;

    If tot > lim then

                    Raiserror 30002 You cannot go over your limit;

    endif

Answers (0)