Execute a stored procedure
-
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?
-
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?
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
-
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?
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/[^]
-
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
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.
-
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?