• Firstly, an explanation of what what you're doing isn't working. Inside your While loop your returning your full dataset, in this case every row that your going to insert, every time you loop through. This means that each time the process runs @NewID is going to have the same value across every row, then you increment the value by one. Then you return the whole data set (again), and every row has the new value of @NewID.

    Using a While Loop or Cursor really isn't the idea here. When using SQL you need to stop thinking with iterative mind set, and think about it in a whole. I apologise that I can't remember who said this (probably Jeff Moden, but whoever it is, please feel free to cite them) but a good saying is "Don't think about what you want to do to a row; think about what you want to do with a column". Your thought process was you need to take the first row and set it the highest value plus one of the current ID. Then go to the nxt row and add one, then the next row and add one. Instead, a dataset solution would be to set the ID to the Row Number in that dataset, and add the highest value from your table to it.

    I've made a small assumption, as theres no sample data, but this should get you the answer you want:
    INSERT INTO [schmeap].[WorkComment_test] ([WorkCommentId1],[WorkId],[Comments],[IsExternalViewable],[IsAlert],[CreatedBy],[CreatedDate],[UpdatedBy],[UpdatedDate],[IsDeleted],[RegistrationId])
    SELECT ROW_NUMBER() OVER (ORDER BY SUBSTRING(w.WINFkey,3,LEN(w.WINFKEY)) + (SELECT MAX([WorkCommentId]) FROM [schemap].[WorkComment]) AS ID, --Total guess what the ORDER should be.
           --The above uses the ROW_NUMBER function, to give each row its own "ID". I then use your SQL to get the highest ID value from your existing table and add that it it.
           --So, the first row would be allocated ROW_NUMBER. If your existing max ID is 132465, then that equates to 132465 + 1 = 132466.
           SUBSTRING(w.WINFkey,3,LEN(w.WINFKEY)),
           'Legacy Migration Information',
           1,
           1,
           'domain\testuser',
           GETDATE(),
           SYSTEM_USER,
           GETDATE(),
           0,
           0  
    FROM db.schemaI.winf w 
    WHERE last_paid in ( 'L17','L18','L19','L20','L21','L22','L23','L24','L25','L26','L27','L28','L29','L30','L31','L32','L33','L34','L35','L35B','L36A','L36B','L36C','L37A');

    If you have any questions, please ask. The important part is you understand what the above SQL is doing, so you can learn from it. 🙂

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk