INSERT EXEC (SQL Server)
INSERT EXEC (SQL Server) is a SQL statement in the DML Statements category. SQL Server: inserts the result set from a stored procedure directly into a table. The syntax is INSERT INTO table EXEC stored_procedure params;. It returns rows inserted from proc. A typical example: CREATE TABLE #temp_employees (id INT, name VARCHAR(100), salary DECIMAL(10,2)); INSERT INTO #temp_employees EXEC GetEmployeesByDepartment @dept_id = 20; -- Execute stored procedure and capture results -- Can also use INSERT EXEC with dynamic SQL: DECLARE @sql NVARCHAR(MAX) = 'SELECT id, name, salary FROM employees WHERE department_id = @dept'; INSERT INTO #temp_employees EXEC sp_executesql @sql, N'@dept INT', @dept = 20; A close relative is INSERT INTO, which inserts new rows into a table. A close relative is UPDATE, which modifies existing rows in a table. Always use WHERE to avoid updating all rows. A close relative is DELETE, which removes rows from a table. Always use WHERE to avoid deleting all rows.