Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Sybase > sqlstatus option trouble

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-16-03, 09:58
mntamago mntamago is offline
Registered User
 
Join Date: Oct 2002
Location: Tokyo
Posts: 6
Question sqlstatus option trouble

When I try the following SQL, I get the ERRORS
listed below.

======== SQL =======
begin

declare @name varchar(20)

declare nameC cursor
for
select name from dbtable
where
id >=2 and
id <= 4

open nameC
fetch nameC into @name

while (@@sqlstatus = 0 )
begin
select @name
fetch nameC into @name
end

close nameC
deallocate cursor nameC
end
=====================

========ERRORS =======
Mg 7344, Level 15, State 2:
Server 'SYBASE', Line 5:
DECLARE CURSOR must be the only statement in a query batch.
Msg 11721, Level 15, State 1:
Server 'SYBASE', Line 15:
Global variables not allowed as defaults.
=====================

My question is then, how do I set the default
to allow global variables?

I have tried using sp_dboption, but it does not work.

======== sp_dboption ERRORS =======
1> use master
2> sp_dboption testbd, "unique auto_identity index", true
3> go
Msg 102, Level 15, State 1:
Server 'SYBASE', Line 2:
Incorrect syntax near 'sp_dboption'.
=====================

BTW, when I do sp_helpdb testbd reads with "no options set".

Any help/suggestions would be appreciated!
Reply With Quote
  #2 (permalink)  
Old 02-18-03, 17:28
corral corral is offline
Registered User
 
Join Date: Aug 2002
Location: Madrid, Spain
Posts: 83
In plain Transact-SQL you must isolate a
cursor definition in a batch for itself. Remind
that a batch is the bunch of SQL statements
from one "go" line to the next "go" line.
So, you should code:

declare nameC cursor
for
select name from dbtable
where
id >=2 and
id <= 4
go
-- SEE THE "go" above
declare @name varchar(20)
open nameC
...

This forbids the use of local variables in
the cursor definition. IIRC, the only
workaround is to create a stored proc;
more functional cursors are allowed
inside stored procedures.

Regards,
Mariano Corral
Reply With Quote
  #3 (permalink)  
Old 02-21-03, 22:51
mntamago mntamago is offline
Registered User
 
Join Date: Oct 2002
Location: Tokyo
Posts: 6
Creating a stored proc solved the problem very nicely.

Thank you for the info!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On