Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > DECLARE @prefix INT; > SET @prefix = 573071; > WITH > cte1 AS (SELECT 0 num > UNION ALL > SELECT num+1 FROM cte1 WHERE num < 9) > SELECT num, > @prefix*100+num*10+9-((@prefix/100000+(@prefix/1000)%10+(@prefix/10)%10+num)*3+((@prefix/10000)%10+(@prefix/100)%10+@prefix%10)-1)%10 barcode > > FROM cte1; > GO > > <pre> > num | barcode > --: | -------: > 0 | 57307107 > 1 | 57307114 > 2 | 57307121 > 3 | 57307138 > 4 | 57307145 > 5 | 57307152 > 6 | 57307169 > 7 | 57307176 > 8 | 57307183 > 9 | 57307190 > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=d16491561a9d33e161ced2175dfb446d)*
back to fiddle