Re: The cursor is READ ONLY

Re: The cursor is READ ONLY

 

  

Comperatore Craig wrote:
> Hey Gurus - can someone help me figure out why I am getting this error:
>
> Server: Msg 16929, Level 16, State 1, Line 70
> The cursor is READ ONLY.
...
> I've tried adding the FOR UPDATE clause in my set query, but then I get:
> FOR UPDATE cannot be specified on a READ ONLY cursor

Did you use just
FOR UPDATE
or
FOR UPDATE OF p.case_status, p.case_substatus, p.episode_close_date,
p.user_id, p.entry_chron, p.comments
?

The former implies you're asking to update all the fields including the
result fields of your z select, which is obviously impossible as z's
fields are derived aggregate values.

To update with a cursor, you have to have a FOR UPDATE clause in the
declaration and all the targetted fields must be updateable (non-derived
and from a table which you have update permissions on).

As an aside, you should probably use FETCH NEXT INTO (set of local
variables) and use the variables in your UPDATE SET ... WHERE CURRENT OF
statement instead of repeating that FROM clause from the cursor
definition. What you've expressed may be allowed syntax, but I've never
seen it used before and it looks like an invitation for future error.

--
Devin Ben-Hur | President / CTO
eMarket Group, Ltd | http://www.emarket-group.com
Zat.com | http://www.Zat.com
503/445-8028 | mailto:[Email address protected]

At least when a friend shoots you in the face,
you know where he stands.

MS Sql Server LazyDBA home page