Thursday, January 20, 2011

SQL Server: How to Insert Stored Procedure Result Set in a Table

Tables can be populated with data from result set of stored procedure. Method can be applied to regular, temporary and global temporary tables but table variables can not be populated in this fashion.

INSERT INTO [YourTableName](CommaSeparatedColumnsName)
 EXECUTE YourStoredProcedureNameHere CommaSeparatedParameterValues

 Note: Number of input and output columns, as well as their datatypes must be same.

3 comments:

  1. I am regular visitor of blogs, but i must say that content which i find in your blog is outstanding.i will love to visit your blog regularly

    http://supernsetips-news.blogspot.com

    =================================================

    ReplyDelete
  2. How do you get around the error "An INSERT EXEC statement cannot be nested." which inevitably occurs?

    ReplyDelete
  3. http://www.sommarskog.se/share_data.html#INSERTEXEC

    ReplyDelete

All suggestions are welcome