>>> Declare ChartID cursor >>> Forward_Only >>> For >>> Select Distinct >>> (P.ChartID), >>> '0' AS Processed >>> From NTSERVER.IMPACTMD.dbo.Patients P >>> Inner Join NTSERVER.IMPACTMD.dbo.Doc_Header H >>> On H.PatientID = P.PatientID >>>>>>
>>>Msg 16915, Level 16, State 1, Line 43 >>>A cursor with the name 'ChartID' already exists. >>>>>
DECLARE @ChartId int -- or whatever type of ChartID field is Declare ChartID cursor Forward_Only For Select Distinct (P.ChartID)/*, '0' AS Processed, no need of this because this is a constant there is no need to use it in a cursor*/ From NTSERVER.IMPACTMD.dbo.Patients P Inner Join NTSERVER.IMPACTMD.dbo.Doc_Header H On H.PatientID = P.PatientID OPEN ChartID FETCH NEXT FROM ChartID INTO @ChartId WHILE @@FETCH_STATUS = 0 BEGIN --- Do whatever you want to do with @ChartId here FETCH NEXT FROM ChartID INTO @ChartId END CLOSE ChartID DEALLOCATE ChartID