Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 FOR UPDATE cannot be specified on a READ ONLY curs

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-05-24 : 04:18:00
i had a problem with the CURSOR FOR UPDATE option
and i found the solution at:
[url]http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=230723&p=3[/url]
which means to take off fro mthe QUERY the order by!
does any one know's why is that a problem?
why the order by givees me an error on read only cursor?

thnaks in advance
Peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-24 : 05:34:44
why are you using a cursor anyway?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-05-24 : 05:45:51
dont know - that when i usually ask pepole they tell me to use
i will be glad to hear of other solutions!
and of course if you can explain why not to use will be great

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-24 : 05:52:12
well first you have to explain to us what you want to do.
then show us your code.

cursors are bad because they have poor performance compared to set-based operations.
with cursors you're forcing sql server to procedural processing which it isn't intended to do.

changing cursor based code to set based can show a magnitute order of differce in performance.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-05-24 : 06:17:53
what i am doing is i am going over the table on depending on its data i set 1 of the columns (say XXX) to 1 (the default is 0)
later on the rows with the XXX=1 i am using to make diffrent thing like export to text files and so on.
my code :

DECLARE cursor_RB CURSOR SCROLL_LOCKS FOR SELECT Company, Application, Command, EVT , CASE WHEN LEFT(Rtci, 6) = '+97250' THEN 0 ELSE 1 END AS TIT, ICD, CASE WHEN JLMB IS NULL THEN 0 ELSE 1 END as ISTF,ID
,Srde,Rtci,StartDate
FROM M2007 LEFT OUTER JOIN
ORDER BY M2007.SD ASC

FOR UPDATE of is4Billing


OPEN cursor_RB

FETCH NEXT FROM cursor_RB INTO @Company,@Application,@DC,@VET,@IT,@ICGD, @ISF,@ID,@rSdr,@Rtci,@StartDate2

WHILE @@FETCH_STATUS = 0
BEGIN

SET @IDD=0

SELECT @IDD=ID from CM2007
WHERE isUsed=0 AND Srde=@rSdr AND Rtci=@Rtci AND
(StartDate<=@StartDate2+@INTERVAL_TIME)
AND
(StartDate-@StartDate2>=0)
--print @IDD
if @IDD>0
begin
begin Tran
UPDATE CM2007 SET isUsed=1 WHERE ID=@IDD
Commit
end


set @SID=0
select @SID=
case
when Lower(@Company)='fne1' AND @IT=1 then 12
when @IT=1 AND @ISF=1 then 6
when Lower(@Application)='la' then
case
when Lower(@Company)='pt' then 16
when @ISF=1 then 17
when @DC='sgt' then 9
when @DC='sct' then 10
when @DC='semt' then 13
when @DC='sdkt' then 14
when @DC='ssmt' then 19
when @DC='seif' then 20
when @DC='somt' then 21
ELSE 7
end
end



if @SID<>0 AND @SID is Not Null AND @IDD>0
begin
INSERT INTO M2007_Result (id) VALUES(@ID)
exec ( @sqInsert)
End

FETCH NEXT FROM cursor_RB INTO @Company,@Application,@DC,@VET,@IT,@ICGD, @ISF,@ID,@rSdr,@Rtci,@StartDate2
END

CLOSE cursor_RB
DEALLOCATE cursor_RB


what do you mean by "set based "?
can you explain how to do it instead of using cursor's?

thnaks i nadvance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page
   

- Advertisement -