Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.
-
gene #1
Need an advice on 'declare cursor' statement
Hi all
I run next declare cursor statement:
declare c1 cursor
for
select date_modified, event_modified_cd, rec_id
from physicalsecurity
order by date_modified, event_modified_cd, rec_id
for update of date_modified, event_modified_cd, rec_id
.... and I am getting next error:
Server: Msg 16957, Level 16, State 4, Line 3
FOR UPDATE cannot be specified on a READ ONLY cursor.
I tried different options like 'keyset' or 'scroll' - the
same simple problem.
Does anyone know what I am doing wrong?
Thank you, Gene.
gene Guest
-
how to declare the CURSOR in mysql
hi, all I am a green hand of mysql,and I want to declare a cursor in mysql. and I have used the standard SQL statement, but it seems not work. here... -
SQL Statement BETWEEN 2 Dates - Advice Please.
strList = "select * " _ & "from tbltest "_ & "WHERE user LIKE '%" & Replace(strSearch, "'", "''") & "%' AND ID < '2' "_ & "AND IDate Between... -
Insert - Declare Cursor in Proc wont syntax check - help!
Derek, declarqations must be before any other coomands -
cursor 200-problem on mac but not pc? how to swap cursor image?
Hi, I want to hide the cursor in my projector. I've been using "cursor 200" for some time now and it works fine. But now, when I try my projector... -
re-declare (re-use) a cursor in a stored procedure
>> I am looping through cursors in a sproc ... << Why? This means you are using SQL as if it were a 1950's Cobol program. Since you did not post... -
Jane #2
Need an advice on 'declare cursor' statement
It seems that you're missing other necessary components in
the cursor command, e.g. FETCH. Please check SQL
BookOnline.
>-----Original Message-----
>Hi all
>
>I run next declare cursor statement:
>
>declare c1 cursor
>for
>select date_modified, event_modified_cd, rec_id
>from physicalsecurity
>order by date_modified, event_modified_cd, rec_id
>for update of date_modified, event_modified_cd, rec_id
>
>.... and I am getting next error:
>
>Server: Msg 16957, Level 16, State 4, Line 3
>FOR UPDATE cannot be specified on a READ ONLY cursor.
>
>I tried different options like 'keyset' or 'scroll' - the
>same simple problem.
>Does anyone know what I am doing wrong?
>
>Thank you, Gene.
>.
>Jane Guest
-
Mike John #3
Re: Need an advice on 'declare cursor' statement
A cursor containg an ORDER BY is automatically read-only, But you can always do updates with a where clause rather than "current of cursor" to get round it.
Even better lose the cursor and do the process in one statement. Can you post the whole problem and see if someone can remove the need for the cursor?
Mike John
"gene" <gene_golub@hotmail.com> wrote in message news:03f401c3471f$fd4f0b40$a301280a@phx.gbl...> Hi all
>
> I run next declare cursor statement:
>
> declare c1 cursor
> for
> select date_modified, event_modified_cd, rec_id
> from physicalsecurity
> order by date_modified, event_modified_cd, rec_id
> for update of date_modified, event_modified_cd, rec_id
>
> ... and I am getting next error:
>
> Server: Msg 16957, Level 16, State 4, Line 3
> FOR UPDATE cannot be specified on a READ ONLY cursor.
>
> I tried different options like 'keyset' or 'scroll' - the
> same simple problem.
> Does anyone know what I am doing wrong?
>
> Thank you, Gene.Mike John Guest
-
gene #4
Re: Need an advice on 'declare cursor' statement
Thank you Mike
Yes, it's always 'get around' exists.
I had to remove duplicate rows from table and it seemed
the most elegant solution.
I will do that without using cursor.
Thank you for your tip on ordered cursors. I never knew
that.
Gene.
But you can always do updates with a where clause rather>-----Original Message-----
>A cursor containg an ORDER BY is automatically read-only,
than "current of cursor" to get round it.statement. Can you post the whole problem and see if>
>Even better lose the cursor and do the process in one
someone can remove the need for the cursor?news:03f401c3471f$fd4f0b40$a301280a@phx.gbl...>
>Mike John
>
>"gene" <gene_golub@hotmail.com> wrote in messagethe>> Hi all
>>
>> I run next declare cursor statement:
>>
>> declare c1 cursor
>> for
>> select date_modified, event_modified_cd, rec_id
>> from physicalsecurity
>> order by date_modified, event_modified_cd, rec_id
>> for update of date_modified, event_modified_cd, rec_id
>>
>> ... and I am getting next error:
>>
>> Server: Msg 16957, Level 16, State 4, Line 3
>> FOR UPDATE cannot be specified on a READ ONLY cursor.
>>
>> I tried different options like 'keyset' or 'scroll' ->>> same simple problem.
>> Does anyone know what I am doing wrong?
>>
>> Thank you, Gene.
>.
>gene Guest
-
gene #5
Need an advice on 'declare cursor' statement
Thank you Jane for your respond
Other fetch statements were there but I did not even get
to them in a code.
The problem was that 'order by' in a declare cursor makes
this cursor automaticaly 'read only'.
That's were my problem lied.
Thanks again, Gene.
in>-----Original Message-----
>It seems that you're missing other necessary components>the cursor command, e.g. FETCH. Please check SQL
>BookOnline.
>>.>>-----Original Message-----
>>Hi all
>>
>>I run next declare cursor statement:
>>
>>declare c1 cursor
>>for
>>select date_modified, event_modified_cd, rec_id
>>from physicalsecurity
>>order by date_modified, event_modified_cd, rec_id
>>for update of date_modified, event_modified_cd, rec_id
>>
>>.... and I am getting next error:
>>
>>Server: Msg 16957, Level 16, State 4, Line 3
>>FOR UPDATE cannot be specified on a READ ONLY cursor.
>>
>>I tried different options like 'keyset' or 'scroll' - the
>>same simple problem.
>>Does anyone know what I am doing wrong?
>>
>>Thank you, Gene.
>>.
>>
>gene Guest



Reply With Quote

