Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how do i supress cursor select set results Expand / Collapse
Author
Message
Posted Wednesday, February 11, 2009 7:01 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, January 4, 2011 1:28 PM
Points: 30, Visits: 66
Hi all.

I have the following code:


DECLARE prod_cursor CURSOR
FOR
SELECT productid <--Problem child
FROM @products
OPEN prod_cursor
DECLARE @prodid_

FETCH NEXT FROM prod_cursor INTO @prodid_
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF(@@FETCH_STATUS <> -2)
BEGIN
(line by line processing)
END
FETCH NEXT FROM prod_cursor INTO @prodid_
END
CLOSE prod_cursor
DEALLOCATE prod_cursor

SELECT * from @prodid_


Problem is that I am getting the cursor select's result first then the last select's result set. I only want the last result set. Is there a way i can supress the cursor result set?

many thanks



birdie3321
Post #654772
Posted Wednesday, February 11, 2009 7:37 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 12:48 PM
Points: 2,397, Visits: 3,406
Answered here in detail
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=119624



N 56°04'39.16"
E 12°55'05.25"
Post #654818
Posted Wednesday, February 11, 2009 7:56 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, January 4, 2011 1:28 PM
Points: 30, Visits: 66
Thanks peso... I am looking for different solutions...unfortunately i am not a T-SQL wiz and was hoping for something a little more straight forward; e.g., is there an obscure option on the FETCH statement that i could use?
Post #654844
Posted Wednesday, February 11, 2009 8:42 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 12:48 PM
Points: 2,397, Visits: 3,406
As told in other thread, you don't need doubled nested cursors.
All it takes is one update statement and one insert statement.



N 56°04'39.16"
E 12°55'05.25"
Post #654922
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse