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. Execute a stored procedure

Execute a stored procedure

Scheduled Pinned Locked Moved Database
questiondatabase
5 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.
  • J Offline
    J Offline
    John Gathogo
    wrote on last edited by
    #1

    Suppose I have the following stored procedure CREATE PROCEDURE dbo.GetContacts AS SELECT ContactID, ContactName FROM Contacts GO Then I can execute the stored procedure as follows: EXEC dbo.GetContacts How can I receive the returned results into a temporary or permanent table?

    J F M 3 Replies Last reply
    0
    • J John Gathogo

      Suppose I have the following stored procedure CREATE PROCEDURE dbo.GetContacts AS SELECT ContactID, ContactName FROM Contacts GO Then I can execute the stored procedure as follows: EXEC dbo.GetContacts How can I receive the returned results into a temporary or permanent table?

      J Offline
      J Offline
      John ph
      wrote on last edited by
      #2

      John Gathogo wrote:

      SELECT ContactID, ContactName FROM Contacts

      John Gathogo wrote:

      How can I receive the returned results into a temporary or permanent table?

      Using Into Clause Into Temporary Table ---------------------- SELECT ContactID, ContactName INTO #TempTable FROM Contacts The above sql stmt will create a temporary table and Inserts the resulting rows from the query into it. Into Permanent Table ---------------------- Insert Into PermanentTable(ContactID, ContactName)(SELECT ContactID, ContactName FROM Contacts) this statement Inserts the resulting rows from the select query into permanent table provide both the tables should have the same definition.

      Regards
      J O H N :rose:
      "Even eagles need a push." David McNally


      J 1 Reply Last reply
      0
      • J John Gathogo

        Suppose I have the following stored procedure CREATE PROCEDURE dbo.GetContacts AS SELECT ContactID, ContactName FROM Contacts GO Then I can execute the stored procedure as follows: EXEC dbo.GetContacts How can I receive the returned results into a temporary or permanent table?

        F Offline
        F Offline
        Frank Kerrigan
        wrote on last edited by
        #3

        CREATE TABLE #TEMP (ContactID int, ContactName varchar(50)) INSERT #TEMP EXEC dbo.GetContacts SELECT * FROM #TEMP

        Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]

        1 Reply Last reply
        0
        • J John ph

          John Gathogo wrote:

          SELECT ContactID, ContactName FROM Contacts

          John Gathogo wrote:

          How can I receive the returned results into a temporary or permanent table?

          Using Into Clause Into Temporary Table ---------------------- SELECT ContactID, ContactName INTO #TempTable FROM Contacts The above sql stmt will create a temporary table and Inserts the resulting rows from the query into it. Into Permanent Table ---------------------- Insert Into PermanentTable(ContactID, ContactName)(SELECT ContactID, ContactName FROM Contacts) this statement Inserts the resulting rows from the select query into permanent table provide both the tables should have the same definition.

          Regards
          J O H N :rose:
          "Even eagles need a push." David McNally


          J Offline
          J Offline
          John Gathogo
          wrote on last edited by
          #4

          Actually what I meant is that I want to use the stored procedure to populate the table. I already found a way: CREATE @TmpTable (ContactID INT, ContactName NVARCHAR(36)) INSERT INTO @TmpTable EXEC dbo.GetContacts SELECT * FROM @TmpTable Thanks all the same.

          1 Reply Last reply
          0
          • J John Gathogo

            Suppose I have the following stored procedure CREATE PROCEDURE dbo.GetContacts AS SELECT ContactID, ContactName FROM Contacts GO Then I can execute the stored procedure as follows: EXEC dbo.GetContacts How can I receive the returned results into a temporary or permanent table?

            M Offline
            M Offline
            manuo5
            wrote on last edited by
            #5

            create Function [dbo].[MyFun] () Returns @tbl table (id int,Item varchar(100)) as begin insert into @tbl SELECT ContactID, ContactName FROM Contacts return End then use this insert into temporary table/permanent table select * from MyFun() Manu

            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