select
    nr01 as nr01,
    p20  as p20,
    p19  as p19,
    3    as pknd
FROM

(

select
    t1.nr01 as nr01,
    t1.p20 as p20,
    t1.p19 as p19,
    t1.sum1 as sum1,
    t1.sum1/11 as sum21,
    t1.sum1 div 11 as sum22,
    (t1.sum1 div 11)*11 as sum23,
    t1.sum1-(t1.sum1 div 11)*11 as sum24,
    (t1.sum1-(t1.sum1 div 11)*11) mod 10 as sum25,
    t1.v9 as v9
    
FROM 

(


select
   l90.nr01 as nr01,
   l90.p91 as p20,
   l90.p92 as p19,
   cast( substr(l90.p91, 1, 1) as unsigned) * 256
 + cast( substr(l90.p91, 2, 1) as unsigned) * 128
 + cast( substr(l90.p91, 3, 1) as unsigned) * 64
 + cast( substr(l90.p91, 4, 1) as unsigned) * 32
 + cast( substr(l90.p91, 5, 1) as unsigned) * 16
 + cast( substr(l90.p91, 6, 1) as unsigned) * 8
 + cast( substr(l90.p91, 7, 1) as unsigned) * 4
 + cast( substr(l90.p91, 8, 1) as unsigned) * 2   as sum1,

   cast( substr(l90.p91, 9, 1) as unsigned) as v9

from l90
where p904=1


) as t1

) as t2
WHERE v9<>sum25
   || p20=' '
   || length(p20)<>9 ;
