getting results from a cursor in a single table

  • I have a cursor that queries on a table based on a list of IDs.

    The problem I have is for each ID I am getting a seperate result set.

    I want to display the results of each fetch combined in a single result set.

    Can somebody guide?

  • You'd have to store the individual results in some sort of temporary storage (table variable, temp table). Better yet, don't use a cursor. If you are cursoring through a set of data, but you ultimately want to view a set of data as your final results, I would say that you don't need the cursor at all. In fact, using the cursor along with the temporary storage will prove to be slow and cumbersome compared to a set based operation.

    If you want help, post an example of what you are doing and we'll help out. Since you're fairly new, here's a link on how to create a quality post for quality help:

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • It sounds like you need to get rid of the cursor and just run a query using the data in a join or possibly as part of the where clause.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks.

    I tried eliminating the cursor and it works fine now.

    Sorry about my post...I will observe the pattern in my next posting.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply