INSERT INTO [GC].[data].[GC_Config]

SELECT 'len_invoice_number' as Variable, c1 - 1 as Wert FROM

(SELECT TOP 1 len([invoice_number]) as c1, count(*) as c2
FROM [LOCOSOFT].[dbo].[journal_accountings]
WHERE [invoice_number] IS NOT NULL AND len([invoice_number]) > 0
GROUP BY len([invoice_number])
ORDER BY 2 DESC) T1