Sheen
Sheen

Reputation: 3451

How to insert result of stored procedure into a table with extra nullable columns

I have a stored proc returning a set of columns. I want to store the return set into a temp table. I know how to do this: INSERT INTO #TABLE EXEC SP1

Now, the temp table has extra columns that can be NULL. How can I do the same thing and leave the extra columns with NULL values?

Upvotes: 0

Views: 950

Answers (1)

GarethD
GarethD

Reputation: 69819

Just explicitly list the column names you want to insert to:

INSERT #Table (Column1, Column2, Column3)
EXEC SP1;

Example on SQL Fiddle

Which is something I would advocate doing anyway in production code. Aaron Bertrand has written an excellent article as to why:

Upvotes: 5

Related Questions