Re: EXEC statement inside cursor iteration (@@fetch_status =0)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jacco Schalkwijk (NOSPAMjaccos_at_eurostop.co.uk)
Date: 04/20/04


Date: Tue, 20 Apr 2004 14:22:26 +0100

Why do you need a cursor? Is the code in the stored procedure that complex?
Things will be easier and a lot quicker if you don't use a cursor and use
proper SQL instead. If you post your code on here, someone will help you
with that.

Anyways, @@cursor_fetch is not correct Microsoft SQL Server syntax, it's
@@FETCH_STATUS. So if you are actually on a different database platform
(Sybase?), it might more useful to post your questions in forum specific to
that product.

-- 
Jacco Schalkwijk
SQL Server MVP
"R. Z." <bob_whale@yahoo.com> wrote in message
news:34b831f2.0404200357.60733429@posting.google.com...
> I 've have a stored procedure that compares fields across databases.
> In order to do so it requires 2 values it acquires from 2 tables. The
> search is based on the ID of the data owner and a subject:
>
> proc_evaluate_results @StudentId = '222222', Course = 'PSY101'
>
> In order to obtain those values I run a cursor accross my records and
> SELECT THEM INTO 2 @variables, which then replace 222222 and PSY101
> with dynamic values eg.
>
> --define a cursor etc.etc.
>
> WHILE @@cursor_fetch = 0
> BEGIN
>     --do the cursor call INTO @vars
>     EXEC proc_evaluate_results @StudentId = @studentID, @Course =
> @CourseCode
> END
>
> Now,the vars are being passed to the stored procedure and executed OK,
> but the cursor gets stuck on the last record and continues to evaluate
> it until stopped manually.
>
> If I comment out the EXEC and replace it with eg. PRINT @Course + ' |
> '   + @CourseCode it runs fine, exiting after the last record.
>
>
> Thanks
> R>


Relevant Pages

  • Stored procedure does not complete until result set is retrieved from ODBC
    ... I have a SQL Server Stored procedure that I am executing via ODBC. ... -- Start Code without cursor ...
    (microsoft.public.sqlserver.odbc)
  • Re: noise words, @@ERROR, and stop and resume indexing
    ... Could you re-post your SQL script with the cursor code? ... >>Create table Noise ... >>Looking for a SQL Server replication book? ... >>> 1) check noise words inside stored procedure ...
    (microsoft.public.sqlserver.fulltext)
  • Re: "On Error Resume Next" in SQL Server
    ... formatSearchText can output stuff to cause it to fail, ... Pro SQL Server 2000 Database Design - ... > DECLARE TestCursor CURSOR FOR /*WHATEVER*/ ... >>>I am executing a stored procedure that uses a cursor to ...
    (microsoft.public.sqlserver.programming)
  • Re: noise words, @@ERROR, and stop and resume indexing
    ... these words at the beginning before sending them to the cursor. ... Looking for a FAQ on Indexing Services/SQL FTS ... >>Create table Noise ... >>> 1) check noise words inside stored procedure ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Error adding command properties for stored procedure call
    ... I see you are using the SQL Native Client for SQL Server ... A server cursor is not allowed on a remote stored procedure or stored ... The stored procedure called is a test one that simply SELECTs the name field ... int InitializeAndConnect; ...
    (microsoft.public.data.oledb)