0

I have a storedprocedure which has multiple columns. I want to insert only certain columns of this stored procedure into a temp table.

CREATE TABLE #Temp
(
Product VARCHAR(MAX),

)


INSERT INTO #Temp (Product)
EXEC mpaGetProducts

Currently I get the error : "Column name or number of supplied values does not match table definition"

I do not want to insert into one table first and then select only required columns because there is a large amount of data and this would cause a hit on the performance.

I saw this post & a few others online but it wasn't very helpful : Insert results of a stored procedure into a temporary table

Community
  • 1
  • 1
CodeNinja
  • 3,188
  • 19
  • 69
  • 112
  • http://stackoverflow.com/a/35594430/1258492 – RAY Mar 02 '16 at 15:11
  • Possible duplicate of [Select columns from result set of stored procedure](http://stackoverflow.com/questions/209383/select-columns-from-result-set-of-stored-procedure) – Ed Harper Mar 02 '16 at 15:18

2 Answers2

0

What you want is not possible. There is no way to specify the columns you want to select directly from a stored procedure.

EDIT: Actually, a slightly hacky way to do this is with OPENQUERY:

SELECT {Columns that I want}
FROM OPENQUERY(MyServer, 'EXEC MyStoredProc @Params');
Tab Alleman
  • 31,483
  • 7
  • 36
  • 52
0

Please Provide SP Description

If you run your SP the output might have several columns resulting in SELECT STATEMENT so try to mention what column you need to insert into table

arun sai
  • 23
  • 7