Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Use stored procedure in place of select statement for cursor

Use stored procedure in place of select statement for cursor

Scheduled Pinned Locked Moved Database
database
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Khawar Abbas1
    wrote on last edited by
    #1

    I want to use stored procedure in place of select statement for cursor. e.g. DECLARE ProfInd_CURSOR CURSOR for dbo.EM_GET_WORKHOURS 88,1,'01/01/2007','08/08/2007' OPEN ProfInd_CURSOR .............................. any idea

    Do good and have good.

    N E M 3 Replies Last reply
    0
    • K Khawar Abbas1

      I want to use stored procedure in place of select statement for cursor. e.g. DECLARE ProfInd_CURSOR CURSOR for dbo.EM_GET_WORKHOURS 88,1,'01/01/2007','08/08/2007' OPEN ProfInd_CURSOR .............................. any idea

      Do good and have good.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Modest Bird wrote:

      I want to use stored procedure in place of select statement for cursor.

      I don't think that you can do this. What you can do is create a temporary table in your current procedure and fill it from nested procedure. select from this temporary table in cursor


      My Website | Ask smart questions

      1 Reply Last reply
      0
      • K Khawar Abbas1

        I want to use stored procedure in place of select statement for cursor. e.g. DECLARE ProfInd_CURSOR CURSOR for dbo.EM_GET_WORKHOURS 88,1,'01/01/2007','08/08/2007' OPEN ProfInd_CURSOR .............................. any idea

        Do good and have good.

        E Offline
        E Offline
        Eliz k
        wrote on last edited by
        #3

        Hello Modest, You can try to use User Definied Function for your cursor instead of stored procedure. Like this: DECLARE cur CURSOR FORWARD_ONLY READ_ONLY FOR SELECT * FROM dbo.fn_GetTestData(1) Please get the sample from --> http://www.oin1.com/Technical/SQL/FunctionInCursor.htm[^] Eliz.K

        1 Reply Last reply
        0
        • K Khawar Abbas1

          I want to use stored procedure in place of select statement for cursor. e.g. DECLARE ProfInd_CURSOR CURSOR for dbo.EM_GET_WORKHOURS 88,1,'01/01/2007','08/08/2007' OPEN ProfInd_CURSOR .............................. any idea

          Do good and have good.

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          You can't. You have to provide a SELECT statement, and you cannot directly SELECT from a stored procedure's results. You can replace the stored procedure with a user-defined function - either an inline table-valued function, which simply contains a single SELECT statement, or a multistatement table-valued function. Alternatively, the INSERT statement can insert the results of a stored procedure into a table (e.g. INSERT table (columns) EXECUTE stored_proc). You would need to create a temporary table or table variable to store the results, with the appropriate schema, insert into the temporary table/table variable, then declare the cursor to select from that.

          Stability. What an interesting concept. -- Chris Maunder

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups