Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameters for nested cursors from a linked server

Status
Not open for further replies.

RottPaws

Programmer
Mar 1, 2002
478
US
I'm trying to retrieve data for a report using nested cursors. The data is in an Oracle database that is a linked server on the SQL Server.

If I hard-code the query parameters, it works, but I need to make the outer cursor accept parameters from the calling application and the inner cursor accept criteria based on the outer cursor current record.

The example in books online that shows how to do this is using SQL tables.

Since I'm pulling my data from Oracle tables in linked server db, I have to enclose my query in quotes and I haven't been able to find an example of or figure out the syntax to add the outer cursor criteria into the WHERE clause of my query.

My procedure includes the following.

...
OPEN Outer_Cursor

FETCH NEXT FROM Outer_Cursor
INTO @OCCID, @OCLCID, @OCIS

WHILE @@FETCH_STATUS = 0
BEGIN

DECLARE IN_Cursor CURSOR FOR
Select * from OpenQuery(EQ, "
SELECT field1, field2, field3, field4, field5
FROM table1
WHERE field1= @OCCID and
field2= @OCIS")


OPEN IN_Cursor

FETCH NEXT FROM IN_Cursor
INTO @INCID, @INLCID, @INIS, @INDAL

IF @@FETCH_STATUS<>0
PRINT CHAR(9) + &quot;NO Records&quot;
ELSE
PRINT CHAR(9) + &quot;LCID&quot;

WHILE @@FETCH_STATUS = 0
BEGIN
PRINT CHAR(9) + @INLCID
FETCH NEXT FROM IN_Cursor
INTO @INCID, @INLCID, @INIS, @INDAL
END

CLOSE IN_Cursor
DEALLOCATE IN_Cursor

FETCH NEXT FROM OC_Cursor
INTO @OCCID, @OCLCID, @OCIS

END _________
Rott Paws

...It's not a bug. It's an undocumented feature!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top