• This might help you.

    WITH BillingGroups AS(

    SELECT BillingGroupNumber,

    row_number() over (order by BillingGroupNumber) as RowNum

    FROM Sap.DetailsImport

    )

    INSERT INTO [ReceiptRepository].[Lkup].[BillingGroups]

    SELECT BillingGroupNumber,

    'Company' + CAST(RowNum AS varchar(10)),

    'Y',

    'TeraByteMe',

    GETDATE(),

    TeraByteMe,

    GETDATE(),

    '2006-01-01 00:00:00.000',

    '2020-12-31 00:00:00.000'

    FROM BillingGroups

    Now, this might give you repeated billing group numbers, I hope that you're aware of that.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2