Thumb

Insert Stored Procedure output into Temporary Table

9/14/2020 7:19:38 AM

Temporary Table: Temporary tables, are very similar to the permanent tables. Permanent tables get created in the database you specify, and remain in the database permanently until you delete(drop) them. On the other hand, temporary tables get created in the TempDB and are automatically deleted, when they are no longer used.

Different Type of Temporary tables:

  1. Local Temporary tables using #
  2. Global Temporary tables using ##

Now Insert Stored Procedure output into Temporary Table:

/*CREATE PROCEDURE*/
CREATE PROCEDURE GetTemporaryTable
AS
BEGIN
CREATE TABLE #Persons (
    #Id int,
    #Name varchar(250),
);
insert into #Persons values(1,'Jesy')
END
EXEC [dbo].[GetTemporaryTable]

In this stored procedure create a temporary table name as #Persons then insert value into table.