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.
Author |
Topic |
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2013-11-20 : 10:16:58
|
Hi,I am using sql server 2008 R2Can you help me to solve this error please?An INSERT EXEC statement cannot be nested.------------------------------create procedure uspDataGetasselect Code = 'aswe'unionselect Code = 'hgtr'-------------------------------A simplified stored proc.------------------------------create procedure uspDataTEST@Audit bit = 0asdeclare @tblResult table(Code char(10))--populate @tblResult with the returned data from exec uspDataGetinsert into @tblResultexec uspDataGet '' --this stored proc. retrieves one columnif (@Audit = 1) begin select * from @tblResult return endselect 'testdata'----------------------------------declare @Audit bit = 1create table #tblData (Code char(10)) insert into #tblDataexec uspDataTEST @Audit = @Auditselect * from #tblDatadrop table #tblData-----------------------------------Because of business rules, the stored proc. uspDataTEST should not be changed.I know that this error is given because in the calling stored proc. there is insert into ...exec storedprocBut not sure how to solve this error when I call the stored proc.Thank you |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-11-20 : 10:44:09
|
This is a limitation of the insert..exec construct - that you cannot nest them. If you are not able to make changes to the stored procedure, and must insert the data into a table, another alterative would be to use OPENQUERY |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2013-11-25 : 04:57:08
|
How do I use open query in my example please? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|