I have written a Cursor, but the same issue is happening, columnid is not increasing by 1 each time through the loop. Any suggestions?
DECLARE @ColumnID INT
SET @ColumnID = (SELECT MAX([WorkCommentId]) FROM [abc].[WorkComment]) --CurrentID or Row Number
DECLARE @ID INT --Number of Rows to Process
DECLARE IDCursor CURSOR FOR
SELECT DISTINCT COUNT(WINFkey) from dbdb.dbo.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')
OPEN IDCursor
FETCH NEXT FROM IDCursor INTO @ID
WHILE (@@FETCH_STATUS = 0)
BEGIN
--INSERT INTO [PPP].[WorkComment_test] ([WorkCommentId1],[WorkId],[Comments],[IsExternalViewable],[IsAlert],[CreatedBy],[CreatedDate],[UpdatedBy],[UpdatedDate],[IsDeleted],[RegistrationId])
SET @ColumnID = 1 + @ColumnID
SELECT @ColumnID as 'ColumnId'
,SUBSTRING(w.WINFkey,3,LEN(w.WINFKEY))
,'Legacy Migration Information'
,1
,1
,'domain\testuser'
,GETDATE()
,SYSTEM_USER
,GETDATE()
,0
,0
FROM dbdb.dbo.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')
FETCH NEXT FROM IDCursor INTO @ID
END
CLOSE IDCursor
DEALLOCATE IDCursor