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) + "NO Records"
ELSE
PRINT CHAR(9) + "LCID"
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!!!
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) + "NO Records"
ELSE
PRINT CHAR(9) + "LCID"
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!!!