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. Insert into temptable ( #tmp1 ) that execute result from 1 procedure ( return 2 results )

Insert into temptable ( #tmp1 ) that execute result from 1 procedure ( return 2 results )

Scheduled Pinned Locked Moved Database
databasesql-serversysadminquestion
4 Posts 2 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.
  • L Offline
    L Offline
    LTMKH
    wrote on last edited by
    #1

    Dear All, I would like to show you the following questions ( SQL server ): - I have one procedure that return 2 result after execute Eg: create procedure spTest as begin select * from table1 select * from table2 end ( this is just sample procedure that return 2 result after execute ) - I also have one temp Table name #tmpTable1, i want to insert into this temp table, but get result from procedure above, but i can't use this statement: insert into #tmpTable1 exec spTest ( it will not work, because this procedure return 2 result ) Do you have any idea to get result from this procedure into my temp table? Thank you in advance for your good idea...

    Mr. LTM KH

    M 1 Reply Last reply
    0
    • L LTMKH

      Dear All, I would like to show you the following questions ( SQL server ): - I have one procedure that return 2 result after execute Eg: create procedure spTest as begin select * from table1 select * from table2 end ( this is just sample procedure that return 2 result after execute ) - I also have one temp Table name #tmpTable1, i want to insert into this temp table, but get result from procedure above, but i can't use this statement: insert into #tmpTable1 exec spTest ( it will not work, because this procedure return 2 result ) Do you have any idea to get result from this procedure into my temp table? Thank you in advance for your good idea...

      Mr. LTM KH

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      You have a some of choices, the obvious one is to split the child procedure into 2 procs, this is by far the better choice. You could also use a global temp table in the child procs declare as ##TableName. IE create the global temp in the parent proc and call the insert proc, then consume the results in the parent proc. I would consider this a really crappy solution as it is fraught with problems. You could also modify the child proc to use a UNION and return only 1 table (assumes if you are going to insert the data into 1 table then it is the same structure) MS did a great disservice when they allowed multiple result sets to be returned from a single proc.

      Never underestimate the power of human stupidity RAH

      L 1 Reply Last reply
      0
      • M Mycroft Holmes

        You have a some of choices, the obvious one is to split the child procedure into 2 procs, this is by far the better choice. You could also use a global temp table in the child procs declare as ##TableName. IE create the global temp in the parent proc and call the insert proc, then consume the results in the parent proc. I would consider this a really crappy solution as it is fraught with problems. You could also modify the child proc to use a UNION and return only 1 table (assumes if you are going to insert the data into 1 table then it is the same structure) MS did a great disservice when they allowed multiple result sets to be returned from a single proc.

        Never underestimate the power of human stupidity RAH

        L Offline
        L Offline
        LTMKH
        wrote on last edited by
        #3

        Dear Mycroft Holmes, Thanks you so much for your solutions, I will test it with global temp table... But this may not the best choice for me.. Regard

        Mr.LTM-KH

        M 1 Reply Last reply
        0
        • L LTMKH

          Dear Mycroft Holmes, Thanks you so much for your solutions, I will test it with global temp table... But this may not the best choice for me.. Regard

          Mr.LTM-KH

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          LTM_it_kh wrote:

          But this may not the best choice for me.

          It may well be the worst solution! Global temp table are nasty to manage!

          Never underestimate the power of human stupidity RAH

          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