Inserting Data with an EXECUTE Statement

Another option at your disposal is to INSERT data into a table based on the execution of a stored procedure. This enables you to use this data for any other queries or to store the data for later analysis. Other than for storing data for later analysis, you will rarely use this functionality as there are much more efficient ways of storing data for use in other queries. Listing 7.4 shows an example of adding data to a table by using an EXECUTE statement.

Code Listing 7.4. Inserting Data Based on Stored Procedure Execution
 CREATE TABLE TempSPWHO2 ( SPID1 INT, Status VARCHAR(60), Login VARCHAR(16), Hostname VARCHAR(256), BlkBy VARCHAR(3), DBName VARCHAR(256), Command VARCHAR(32), CPUTime INT, DiskIO ...

Get Writing Stored Procedures for Microsoft SQL Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.