Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 INSERT from EXEC stored and other fixed fields
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

232 Posts

Posted - 06/11/2013 :  10:19:17  Show Profile  Reply with Quote
Hello all,
I have a table like this:

ID - FKID - Title1 - Title2 - Value - ModifiedDate

Now I have to perform an INSERT in this table
where the fields Title1,Title2,Value come from
a stored procedure calling, and FKID is a
variable in the scope of a stored procedure
where this Insert is performed (ModifiedDate is GETUTCDATE()).

How can I perform this?

Thanks in advance.


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 06/11/2013 :  10:41:20  Show Profile  Reply with Quote
The first thing that comes to mind - INSERT-EXEC would not work in your case because the columns in the insert part of the statement must exactly match the columns coming out of the EXEC part (the stored proc).

You could try open rowset. There are few examples here

If you have not already, you would need to enable Ad Hoc Distributed queries

sp_configure 'Show Advanced Options', 1
sp_configure 'Ad Hoc Distributed Queries', 1

Another option is to insert the data from the stored proc into a temp table with columns that exactly match the stored procedure record set and then move that into your target table appending the additional columns as required.
Go to Top of Page

Posting Yak Master

232 Posts

Posted - 06/11/2013 :  11:21:33  Show Profile  Reply with Quote
Maybe the solution with a temporary table could be better.

I'll try.

Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 06/11/2013 :  12:32:03  Show Profile  Reply with Quote
yep..that would be recommended approach as otherwise you may have to use distributed query methods

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000