SET TERM ^ ;

CREATE OR ALTER trigger ttbgrade_b01iu for tbgrade
active before insert or update position 0
AS
BEGIN

    IF (NEW.T01 = '' AND NEW.T02 = '' AND NEW.T03 = '' AND NEW.T04 = '' AND NEW.T05 = '' AND
        NEW.T06 = '' AND NEW.T07 = '' AND NEW.T08 = '' AND NEW.T09 = '' AND NEW.T10 = '' AND
        NEW.T11 = '' AND NEW.T12 = '' AND NEW.T13 = '' AND NEW.T14 = '' AND NEW.T15 = '' AND
        NEW.T16 = '' AND NEW.T17 = '' AND NEW.T18 = '' AND NEW.T19 = '' AND NEW.T20 = '') THEN
    BEGIN

        EXCEPTION "..." 'NENHUMA TAMANHO PREENCHIDO. OPERACAO NAO AUTORIZADA!';

    END ELSE
    IF ((NEW.T01 = '' AND (NEW.T02 <> '' OR NEW.T03 <> '' OR NEW.T04 <> '' OR NEW.T05 <> '' OR NEW.T06 <> '' OR NEW.T07 <> '' OR NEW.T08 <> '' OR NEW.T09 <> '' OR NEW.T10 <> '' OR NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T02 = '' AND (NEW.T03 <> '' OR NEW.T04 <> '' OR NEW.T05 <> '' OR NEW.T06 <> '' OR NEW.T07 <> '' OR NEW.T08 <> '' OR NEW.T09 <> '' OR NEW.T10 <> '' OR NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T03 = '' AND (NEW.T04 <> '' OR NEW.T05 <> '' OR NEW.T06 <> '' OR NEW.T07 <> '' OR NEW.T08 <> '' OR NEW.T09 <> '' OR NEW.T10 <> '' OR NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T04 = '' AND (NEW.T05 <> '' OR NEW.T06 <> '' OR NEW.T07 <> '' OR NEW.T08 <> '' OR NEW.T09 <> '' OR NEW.T10 <> '' OR NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T05 = '' AND (NEW.T06 <> '' OR NEW.T07 <> '' OR NEW.T08 <> '' OR NEW.T09 <> '' OR NEW.T10 <> '' OR NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T06 = '' AND (NEW.T07 <> '' OR NEW.T08 <> '' OR NEW.T09 <> '' OR NEW.T10 <> '' OR NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T07 = '' AND (NEW.T08 <> '' OR NEW.T09 <> '' OR NEW.T10 <> '' OR NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T08 = '' AND (NEW.T09 <> '' OR NEW.T10 <> '' OR NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T09 = '' AND (NEW.T10 <> '' OR NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T10 = '' AND (NEW.T11 <> '' OR NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T11 = '' AND (NEW.T12 <> '' OR NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T12 = '' AND (NEW.T13 <> '' OR NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T13 = '' AND (NEW.T14 <> '' OR NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T14 = '' AND (NEW.T15 <> '' OR NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T15 = '' AND (NEW.T16 <> '' OR NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T16 = '' AND (NEW.T17 <> '' OR NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T17 = '' AND (NEW.T18 <> '' OR NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T18 = '' AND (NEW.T19 <> '' OR NEW.T20 <> '')) OR
        (NEW.T19 = '' AND (NEW.T20 <> ''))) THEN
    BEGIN

        EXCEPTION "..." 'ATENCAO! NAO PODEM HAVER INTERVALOS VAZIOS ENTRE OS TAMANHOS.';

    END ELSE
    IF ((NEW.T01 <> '' AND ((NEW.T01 = NEW.T02) OR (NEW.T01 = NEW.T03) OR (NEW.T01 = NEW.T04) OR (NEW.T01 = NEW.T05) OR (NEW.T01 = NEW.T06) OR (NEW.T01 = NEW.T07) OR (NEW.T01 = NEW.T08) OR (NEW.T01 = NEW.T09) OR (NEW.T01 = NEW.T10) OR (NEW.T01 = NEW.T11) OR (NEW.T01 = NEW.T12) OR (NEW.T01 = NEW.T13) OR (NEW.T01 = NEW.T14) OR (NEW.T01 = NEW.T15) OR (NEW.T01 = NEW.T16) OR (NEW.T01 = NEW.T17) OR (NEW.T01 = NEW.T18) OR (NEW.T01 = NEW.T19) OR (NEW.T01 = NEW.T20))) OR
        (NEW.T02 <> '' AND ((NEW.T02 = NEW.T03) OR (NEW.T02 = NEW.T04) OR (NEW.T02 = NEW.T05) OR (NEW.T02 = NEW.T06) OR (NEW.T02 = NEW.T07) OR (NEW.T02 = NEW.T08) OR (NEW.T02 = NEW.T09) OR (NEW.T02 = NEW.T10) OR (NEW.T02 = NEW.T11) OR (NEW.T02 = NEW.T12) OR (NEW.T02 = NEW.T13) OR (NEW.T02 = NEW.T14) OR (NEW.T02 = NEW.T15) OR (NEW.T02 = NEW.T16) OR (NEW.T02 = NEW.T17) OR (NEW.T02 = NEW.T18) OR (NEW.T02 = NEW.T19) OR (NEW.T02 = NEW.T20))) OR
        (NEW.T03 <> '' AND ((NEW.T03 = NEW.T04) OR (NEW.T03 = NEW.T05) OR (NEW.T03 = NEW.T06) OR (NEW.T03 = NEW.T07) OR (NEW.T03 = NEW.T08) OR (NEW.T03 = NEW.T09) OR (NEW.T03 = NEW.T10) OR (NEW.T03 = NEW.T11) OR (NEW.T03 = NEW.T12) OR (NEW.T03 = NEW.T13) OR (NEW.T03 = NEW.T14) OR (NEW.T03 = NEW.T15) OR (NEW.T03 = NEW.T16) OR (NEW.T03 = NEW.T17) OR (NEW.T03 = NEW.T18) OR (NEW.T03 = NEW.T19) OR (NEW.T03 = NEW.T20))) OR
        (NEW.T04 <> '' AND ((NEW.T04 = NEW.T05) OR (NEW.T04 = NEW.T06) OR (NEW.T04 = NEW.T07) OR (NEW.T04 = NEW.T08) OR (NEW.T04 = NEW.T09) OR (NEW.T04 = NEW.T10) OR (NEW.T04 = NEW.T11) OR (NEW.T04 = NEW.T12) OR (NEW.T04 = NEW.T13) OR (NEW.T04 = NEW.T14) OR (NEW.T04 = NEW.T15) OR (NEW.T04 = NEW.T16) OR (NEW.T04 = NEW.T17) OR (NEW.T04 = NEW.T18) OR (NEW.T04 = NEW.T19) OR (NEW.T04 = NEW.T20))) OR
        (NEW.T05 <> '' AND ((NEW.T05 = NEW.T06) OR (NEW.T05 = NEW.T07) OR (NEW.T05 = NEW.T08) OR (NEW.T05 = NEW.T09) OR (NEW.T05 = NEW.T10) OR (NEW.T05 = NEW.T11) OR (NEW.T05 = NEW.T12) OR (NEW.T05 = NEW.T13) OR (NEW.T05 = NEW.T14) OR (NEW.T05 = NEW.T15) OR (NEW.T05 = NEW.T16) OR (NEW.T05 = NEW.T17) OR (NEW.T05 = NEW.T18) OR (NEW.T05 = NEW.T19) OR (NEW.T05 = NEW.T20))) OR
        (NEW.T06 <> '' AND ((NEW.T06 = NEW.T07) OR (NEW.T06 = NEW.T08) OR (NEW.T06 = NEW.T09) OR (NEW.T06 = NEW.T10) OR (NEW.T06 = NEW.T11) OR (NEW.T06 = NEW.T12) OR (NEW.T06 = NEW.T13) OR (NEW.T06 = NEW.T14) OR (NEW.T06 = NEW.T15) OR (NEW.T06 = NEW.T16) OR (NEW.T06 = NEW.T17) OR (NEW.T06 = NEW.T18) OR (NEW.T06 = NEW.T19) OR (NEW.T06 = NEW.T20))) OR
        (NEW.T07 <> '' AND ((NEW.T07 = NEW.T08) OR (NEW.T07 = NEW.T09) OR (NEW.T07 = NEW.T10) OR (NEW.T07 = NEW.T11) OR (NEW.T07 = NEW.T12) OR (NEW.T07 = NEW.T13) OR (NEW.T07 = NEW.T14) OR (NEW.T07 = NEW.T15) OR (NEW.T07 = NEW.T16) OR (NEW.T07 = NEW.T17) OR (NEW.T07 = NEW.T18) OR (NEW.T07 = NEW.T19) OR (NEW.T07 = NEW.T20))) OR
        (NEW.T08 <> '' AND ((NEW.T08 = NEW.T09) OR (NEW.T08 = NEW.T10) OR (NEW.T08 = NEW.T11) OR (NEW.T08 = NEW.T12) OR (NEW.T08 = NEW.T13) OR (NEW.T08 = NEW.T14) OR (NEW.T08 = NEW.T15) OR (NEW.T08 = NEW.T16) OR (NEW.T08 = NEW.T17) OR (NEW.T08 = NEW.T18) OR (NEW.T08 = NEW.T19) OR (NEW.T08 = NEW.T20))) OR
        (NEW.T09 <> '' AND ((NEW.T09 = NEW.T10) OR (NEW.T09 = NEW.T11) OR (NEW.T09 = NEW.T12) OR (NEW.T09 = NEW.T13) OR (NEW.T09 = NEW.T14) OR (NEW.T09 = NEW.T15) OR (NEW.T09 = NEW.T16) OR (NEW.T09 = NEW.T17) OR (NEW.T09 = NEW.T18) OR (NEW.T09 = NEW.T19) OR (NEW.T09 = NEW.T20))) OR
        (NEW.T10 <> '' AND ((NEW.T10 = NEW.T11) OR (NEW.T10 = NEW.T12) OR (NEW.T10 = NEW.T13) OR (NEW.T10 = NEW.T14) OR (NEW.T10 = NEW.T15) OR (NEW.T10 = NEW.T16) OR (NEW.T10 = NEW.T17) OR (NEW.T10 = NEW.T18) OR (NEW.T10 = NEW.T19) OR (NEW.T10 = NEW.T20))) OR
        (NEW.T11 <> '' AND ((NEW.T11 = NEW.T12) OR (NEW.T11 = NEW.T13) OR (NEW.T11 = NEW.T14) OR (NEW.T11 = NEW.T15) OR (NEW.T11 = NEW.T16) OR (NEW.T11 = NEW.T17) OR (NEW.T11 = NEW.T18) OR (NEW.T11 = NEW.T19) OR (NEW.T11 = NEW.T20))) OR
        (NEW.T12 <> '' AND ((NEW.T12 = NEW.T13) OR (NEW.T12 = NEW.T14) OR (NEW.T12 = NEW.T15) OR (NEW.T12 = NEW.T16) OR (NEW.T12 = NEW.T17) OR (NEW.T12 = NEW.T18) OR (NEW.T12 = NEW.T19) OR (NEW.T12 = NEW.T20))) OR
        (NEW.T13 <> '' AND ((NEW.T13 = NEW.T14) OR (NEW.T13 = NEW.T15) OR (NEW.T13 = NEW.T16) OR (NEW.T13 = NEW.T17) OR (NEW.T13 = NEW.T18) OR (NEW.T13 = NEW.T19) OR (NEW.T13 = NEW.T20))) OR
        (NEW.T14 <> '' AND ((NEW.T14 = NEW.T15) OR (NEW.T14 = NEW.T16) OR (NEW.T14 = NEW.T17) OR (NEW.T14 = NEW.T18) OR (NEW.T14 = NEW.T19) OR (NEW.T14 = NEW.T20))) OR
        (NEW.T15 <> '' AND ((NEW.T15 = NEW.T16) OR (NEW.T15 = NEW.T17) OR (NEW.T15 = NEW.T18) OR (NEW.T15 = NEW.T19) OR (NEW.T15 = NEW.T20))) OR
        (NEW.T16 <> '' AND ((NEW.T16 = NEW.T17) OR (NEW.T16 = NEW.T18) OR (NEW.T16 = NEW.T19) OR (NEW.T16 = NEW.T20))) OR
        (NEW.T17 <> '' AND ((NEW.T17 = NEW.T18) OR (NEW.T17 = NEW.T19) OR (NEW.T17 = NEW.T20))) OR
        (NEW.T18 <> '' AND ((NEW.T18 = NEW.T19) OR (NEW.T18 = NEW.T20))) OR
        (NEW.T19 <> '' AND ((NEW.T19 = NEW.T20)))) THEN
    BEGIN
    
        EXCEPTION "..." 'ATENCAO! NAO PODEM HAVER DESCRICOES IGUAIS NOS TAMANHOS DA GRADE.';

    END

END
^

SET TERM ; ^

