Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Clearing Cursors
Message
From
11/06/2008 15:30:06
 
 
To
11/06/2008 15:20:08
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
General information
Forum:
Microsoft SQL Server
Category:
Scripting
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01323202
Message ID:
01323248
Views:
12
This message has been marked as a message which has helped to the initial question of the thread.
>>>This is the only thing other than a declare statement in this particular script, but each time I run it I get the error listed at the bottom.
>>>
>>>
>>>	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.
>>>
>>
>>Please do not star with CURSORS.
>>They sounds great for VFP developers but they are performance killers.
>>SQL Server is a SET based language , so you better use rowsets instead of rows.
>
>Sounds good, but this is a one-time thing to convert some data. Looks like they aren't useful to me anyway as you can't seem to select from them after they are created.

You can't SELECT From CURSORS you only can FETCH next record ang get what you need in variables.

So in your case:
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 
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform