• I'm not sure exactly what this query should be doing, but if you question is how to use insert with row_number then just do this:

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

    select M.RowNum, M.BillingGroupNumber

    from

    (

    select BillingGroupNumber, (row_number() over (order by BillingGroupNumber) - 1) % @Counter + 1 as RowNum

    from Sap.DetailsImport

    ) as M

    I'm not sure what the other variables are used for or why this is in a while loop.



    Microsoft Certified Master - SQL Server 2008
    Follow me on twitter: @keith_tate

    Forum Etiquette: How to post data/code on a forum to get the best help[/url]