If your exdiff is a small number, you can create a virtual table of numbers using SELECT..UNION ALL , as shown here, and join it:
select prevdoc+number from doc join (select 1 number union all select 2 union all select 3 union all select 4 union all select 5) x on x.number <= doc.exdiff order by 1;
I provided 5, but you can expand them as needed. You did not specify your DBMS, but in each of them there will be a source of sequential numbers, for example, in SQL Server, you can use:
select prevdoc+number from doc join master..spt_values v on v.number <= doc.exdiff and v.number >= 1 and v.type = 'p' order by 1;
The master..spt_values ββtable contains numbers from 0 to 2047 (when filtering by type = 'p').
source share