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)
 Nested Cursor failed..

Author  Topic 

amigosnw
Starting Member

1 Post

Posted - 2002-09-06 : 13:59:11
This script is only looping through the first iteration of the first cursor, but will iterate through the second successfully. Any suggestions?
Here's the script:
DECLARE @iCompanyId AS INT
DECLARE @iIndividualId AS INT
DECLARE @iSiteId AS INT
SET @iSiteId = 1
DECLARE com_Cursor CURSOR FOR SELECT iCompanyId FROM #tempCompany
OPEN com_Cursor
FETCH NEXT FROM com_Cursor INTO @iCompanyId
--WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE ind_Cursor CURSOR FOR SELECT iContactId FROM #tempContacts
OPEN ind_Cursor
FETCH NEXT FROM ind_Cursor INTO @iIndividualId
BEGIN
EXEC wbospsiContact @iSiteId,
Null,
@iIndividualId,
@iCompanyId,
47,
Null,
'RshInsert',
Null, 1,
1, Null,
'RshInsert'
FETCH NEXT FROM ind_Cursor INTO @iIndividualId
END
CLOSE ind_Cursor
DEALLOCATE ind_Cursor
FETCH NEXT FROM com_Cursor INTO @iCompanyId
END
CLOSE com_Cursor
DEALLOCATE com_Cursor

1fred
Posting Yak Master

158 Posts

Posted - 2002-09-06 : 14:13:13
can it be because you are not looping trought your second cursor, so when it comes to the fetch your variable @@fetch_status takes 1. Because there is only one variable for the 2 cursor, it is like a global variable.

Go to Top of Page
   

- Advertisement -