Inserting Data From Store Procedure

Step 1

Creating the Student Table:

  1. CREATE TABLE Student  
  2. (   
  3. ID INT IDENTITY(1,1) PRIMARY KEY,  
  4. FirstName VARCHAR(50),  
  5. LastName VARCHAR(50),  
  6. Marks INT   
  7. )  
Step 2

Inserting the some sample data:
  1. INSERT INTO Student (FirstName,LastName,Marks) VALUES('rakesh','kalluri',500)  
  2. INSERT INTO Student (FirstName,LastName,Marks) VALUES('Ali','MD',600)  
  3. INSERT INTO Student (FirstName,LastName,Marks) VALUES('Raju','Ganga',700)  
Step 3

Create procedure with out parameters:
  1. CREATE PROCEDURE Get_StudentInformation  
  2. AS  
  3. BEGIN  
  4. SELECT * FROM Student  
  5. END  
Step 4

Create Student table in Tempdb:
  1. CREATE TABLE Tempdb.#Student  
  2. (   
  3. ID INT ,  
  4. FirstName VARCHAR(50),  
  5. LastName VARCHAR(50),  
  6. Marks INT   
  7. )  
Step 5

Inserting data from stored procedure to Temp Table:
  1. INSERT INTO Tempdb.#Student  
  2. EXEC Get_StudentInformation  
Step 6

Select data from Temp Table:
  1. SELECT * FROM Tempdb.#Student  
Step 7

Truncating Temp Table:
  1. TRUNCATE TABLE Tempdb.#Student  
Step 8

Create procedure with parameters:
  1. CREATE PROCEDURE Get_StudentInformationWithID  
  2. (@In_ID int)  
  3. AS  
  4. BEGIN  
  5. SELECT * FROM Student where ID= @In_ID  
  6. END  
Step 9

Inserting data from stored procedure with parameter to Temp Table:
  1. INSERT INTO Tempdb.#Student  
  2. EXEC Get_StudentInformationWithID 1  
Step 10

Select data from Temp Table:
  1. SELECT * FROM Tempdb.#Student  
table

Step 11

Drop Temp Table:
  1. DROP TABLE Tempdb.#Student