SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

Ciupaz
Posting Yak Master

Italy
227 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.

Luigi

James K
Flowing Fount of Yak Knowledge

3323 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 http://msdn.microsoft.com/en-us/library/ms190312.aspx

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

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


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

Ciupaz
Posting Yak Master

Italy
227 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.

Lugi
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 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

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.03 seconds. Powered By: Snitz Forums 2000