cursor

  • Hi,

    can someone share a simple stored procedure example to pass table name as output and output as cursor ?

    sample query need to use in procuderure:

    SELECT top 10 name from sys.objects

    i want to pass table name as input and the output resultset to be stored in cursor.

    Thanks,

    Kumar

  • skrknarayana (9/11/2014)


    Hi,

    can someone share a simple stored procedure example to pass table name as output and output as cursor ?

    sample query need to use in procuderure:

    SELECT top 10 name from sys.objects

    i want to pass table name as input and the output resultset to be stored in cursor.

    Thanks,

    Kumar

    A cursor is not a storage mechanism. It is a very slow way to traverse rows one at a time. It is unclear what you want. Your query for sys.objects would only return 1 row if you filter that to a tablename.

    What are you really trying to do here? We can help find a solution that is not using a cursor.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • If my guessing skills are working fine, you want a result set which in some coding languages is called a cursor. A cursor in SQL Server is very different and can't be returned as an output from a stored procedure.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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