Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

An INSERT EXEC statement cannot be nested.Please tel me some good way of formulation in following situation.

$
0
0

Hi,

    The following query is showing error An INSERT EXEC statement cannot be nested

CREATE PROCEDURE [dbo].[Procedur3] @para1 int AS BEGIN CREATE TABLE #tem (…. …. ) select * from detialpar where did=@para1 --this code is quite big and is called from many place so we kept it inside this SP , so that we can call the sp to get result. END CREATE PROCEDURE [dbo].[Procedur2] @para1 int @para2 datetime AS BEGIN CREATE TABLE #tem ( …. …. ) insert into #tem (value) exec [dbo].[Procedure3] @para1 exec ('select * from abc left join #tem on id=temid where id =' + cast(@para1 as varchar) -- i do not want to change this big dynamic query, because it has many optonal code concatinated by using "if then else". END ---- CREATE PROCEDURE [dbo].[Procedure1] @para1 int, @para2 datetime AS BEGIN delete from table1 where id=@para1 insert into table1 ( col1,col2) exec Procedure2 @para1,@para2 …….. ……. There are many blocks in this SP where we are deleting and inserting

with different SP . …….. select Name,Amount from #Temp1 END ------------ CREATE PROC Procedure AS BEGIN SET TRANSACTION ISOLATION LEVEL SNAPSHOT SET NOCOUNT ON LOOP "A" starts here which gests id from a table xyz @para1 begin try begin trans exec [Procedure1] @para1 LOOP "A" ents here COMMIT TRANSACTION; END TRY BEGIN CATCH IF @@trancount > 0 ROLLBACK TRANSACTION; END CATCH; END GO

Please tel me some good way of solving the error.

yours sincerly


Viewing all articles
Browse latest Browse all 23857

Trending Articles