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)
 Cursor Problem

Author  Topic 

Crispy2010
Starting Member

2 Posts

Posted - 2010-10-03 : 17:30:43
Hi Guys,

I've encountered the following problem and After several tests I'm still struggling.

If I Run:
---------------------------------------------
SELECT Cuenta_Suc, Cuenta_Tipo, Cuenta_Nume, Monto_Aplicado, Monto_Aplicado_ME, Monto_Bloqueo, ID_Bloqueo, Ofic_Numero, Tipo_PzoFijo, Cotizacion
FROM DBO.TABLE
---------------------------------------------
I get 27000+ Rows

If I run a Cursor
---------------------------------------------
-- Also Tried Static
-- keyset
-- FORWARD_ONLY OPTIMISTIC
-- with same result
DECLARE curSBLin1 CURSOR
FOR
SELECT Cuenta_Suc, Cuenta_Tipo, Cuenta_Nume, Monto_Aplicado, Monto_Aplicado_ME, Monto_Bloqueo, ID_Bloqueo, Ofic_Numero, Tipo_PzoFijo, Cotizacion
FROM DBO.TABLE

open curSBLin1;

WHILE (@@FETCH_STATUS <> -1) -- Tried also @@FETCH_STAUTS = 0
BEGIN
FETCH NEXT from curSBLin1;
END


close curSBLin1;
Deallocate curSBLin1
---------------------------------------------

I get 0 (zero) rows.

Any thoughts???

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-03 : 18:31:51
You need to put some code inside the WHILE loop. What do you intend to do with each row?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Crispy2010
Starting Member

2 Posts

Posted - 2010-10-03 : 23:14:01
Hi Tara,

Yes, off course.

The actual SP is much bigger, but since that simple query in the SQL Query analyzer is not producing any output...there was no point in posting the whole SP.

The SP is supposed to open a subset of records from a Table, process each record and call another SP to insert certain records in another table.

Since a manual debug and a complete debug with the SQL Ultimate Debugger got me to determine that the Cursor is empty i started by trying the "Select query" by itself with all the conditions in the where clause.

Since the cursor was still empty, I tried running it with no conditions set in the where clause.

And I get no records, none.

Thats when I posted considering that the cursor declaration might be wrong, or speculating that maybe someone came across this situation in the past.

I've being writing similar code for 15+ years and its a first for me...but there's always a first ;-)

any help is appreciated.

Thanks

Gustavo

PS: If you think the rest of the code might be in the way I can post it off course.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-03 : 23:27:23
The code that you posted so far is fine. You won't get any output as your code isn't doing anything.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2010-10-04 : 08:50:28
after opening the cursor....should you not be fetching the 1st record?
Go to Top of Page
   

- Advertisement -