1
Declare @tempTableVariable Table(
    email varchar(50)
)

Insert INTO @tempTableVariable 
EXEC GetData

select email
from @tempTableVariable

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

Is there a simple way of getting a subset from GetData without explicitly declaring all the fields in the table variable declaration?

  • See http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure[enter link description here][1] [1]: http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure – Slippery Pete Oct 26 '12 at 19:38

1 Answers1

0

If you don't have control over the GetData stored procedure, I don't think there is any way you can get around having to declare all the fields in your table variable.

If you can control GetData, you could add a parameter to it that when equal to 1 would returnt the results the way you want them, and otherwise would do what it does currently.

I'll mention it for the sake of completeness, but there are lots of other options besides INSERT EXEC. http://www.sommarskog.se/share_data.html is a great explanation of the options.

csm8118
  • 1,213
  • 9
  • 11