Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,I have below code block and procedure returns multiple columns and my temp table have only 1 column.. Can I run multiple columns insertion?
ALTER PROC testprocASBEGIN SELECT 1 AS ids, 2 AS numsENDGO-- Insert new recordsCREATE TABLE #tmpOGroup (OrgGroupID INT)INSERT #tmpOGroup (OrgGroupID) EXEC testprocSELECT * FROM #tmpOGroup DROP TABLE #tmpOGroup
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-09-17 : 10:09:40
I haven't tried it the way you are doing it, but I suspect you cannot do this. The only workaround I can think of is to create an intermediate temporary table with two columns to insert into and then read the column that you want from that temp table.Also, while I myself am guilty of using the INSERT..EXEC, the more read about it, the less I am a fan of that approach. For example, see these blogs by two people whose opinions are very well-respected and reliable:http://www.sommarskog.se/share_data.html#INSERTEXEChttp://sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx
Yes sunitabeck, thats true.. I will check those blogs..and Thanks visakh for your link and input.
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2012-09-18 : 11:09:39
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/