SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how do i supress cursor select set results


how do i supress cursor select set results

Author
Message
brd123
brd123
SSC-Enthusiastic
SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)

Group: General Forum Members
Points: 176 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
SwePeso
SwePeso
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9843 Visits: 3433
Answered here in detail
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=119624


N 56°04'39.16"
E 12°55'05.25"
brd123
brd123
SSC-Enthusiastic
SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)

Group: General Forum Members
Points: 176 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?
SwePeso
SwePeso
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9843 Visits: 3433
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"
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search