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

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

You can not do like above:
Try the below:(Not tested), Below, we do not change the code, however, we placed your dynamic execution to different procedure.
CREATE PROCEDURE [dbo].[Procedur3]
@para1 int
AS
BEGIN
CREATE TABLE #tem
insert into #tem (value)
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
exec [dbo].[Procedure3] @para1
END
CREATE PROCEDURE [dbo].[Procedure1]
@para1 int,
@para2 datetime
AS
BEGIN
delete from table1 where id=@para1
insert into table1 ( col1,col2)
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".
……. 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

Similar Messages

  • INSERT EXEC Statement Cannot Be Nested

    I AM GETTING THE FOLLOWING PROBLEM WHEN I EXECUTE THIS QUERY:
    DECLARE @i INT
    DECLARE @Lenght INT;
    DECLARE @Publication VARCHAR(MAX)
    DECLARE @ReplicationMonitor  TABLE 
    id int identity,
    status int
    ,warning int
    ,subscriber sysname null
    ,subscriber_db sysname
    ,publisher_db sysname
    ,publication sysname
    ,publication_type int
    ,subtype int
    ,latency int
    ,latencythreshold int
    ,agentnotrunning int
    ,agentnotrunningthreshold int
    ,timetoexpiration int
    ,expirationthreshold int            
    ,last_distsync datetime
    ,distribution_agentname sysname  null
    ,mergeagentname sysname null
    ,mergesubscriptionfriendlyname sysname null
    ,mergeagentlocation sysname null
    ,mergeconectiontype int
    ,mergePerformance int null
    ,mergerunspeed float null 
    ,mergerunduration int null
    ,monitorranking int       
    ,distributionagentjobid  binary(16) null
    ,mergeagentjobid binary(16) null
    ,distributionagentid int null
    ,distributionagentprofileid int null
    ,mergeagentid int null
    ,mergeagentprofileid int null
    ,logreaderagentname sysname null           
    ,publisher sysname null           
    DECLARE @Publications table
    Id INT IDENTITY ,
    Publication VARCHAR (MAX )
    INSERT INTO @Publications (Publication)
    SELECT Name FROM sysmergepublications
    SET @i =  (SELECT MIN (Id) FROM @Publications);
    SET @Lenght = (SELECT COUNT (*) FROM @Publications);
    WHILE (@i <= @Lenght)
    BEGIN
    SELECT @Publication = Publication
    FROM @Publications WHERE Id = @i;
    BEGIN TRY
    BEGIN TRANSACTION
    INSERT INTO @ReplicationMonitor 
    EXEC [distribution].dbo.sp_replmonitorhelpsubscription 
    @publication = @Publication,
    @publisher =  '',
    @publisher_db =  '',
    @publication_type = 2
    COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
    ROLLBACK TRANSACTION;
    PRINT ERROR_MESSAGE(); 
    END CATCH
    SET @i = @i + 1;
    END;
    SELECT * FROM @ReplicationMonitor
    SO, IF YOU CAN HELP ME ILL BE APRECIATE IT, AND THANK YOU A LOT !!!

    As i mentioned you, i have found a solution for this issue, the solution is very strange because for me... it is a sql server bug and i cannot explaint but... i have discovered that we have to execute the procedure lonely before to execute it on the loop..
    but why ? i dont know actually.
    i cannot give you an explain for this strange behavior but it have resolved my problem.....
    in my case the first execution does not throws any problem because i send null values inthe parameters, so i am performing a validation on the table variable when the result set from´is inserted on it from the procedure execution on the loop, for this reaseon
    the first execution it does not matter.
    The code......
    DECLARE @i INT
    DECLARE @Lenght INT;
    DECLARE @Publication VARCHAR(MAX)
    DECLARE @Query NVARCHAR(MAX)
    DECLARE @Database NVARCHAR(50);
    DECLARE @Server NVARCHAR(50);
    SET @Database =DB_NAME();
    SET @Server  =@@SERVERNAME;
    DECLARE @ReplicationMonitor  TABLE 
    --id int identity,
    status int
    ,warning int
    ,subscriber sysname null
    ,subscriber_db sysname
    ,publisher_db sysname
    ,publication sysname
    ,publication_type int
    ,subtype int
    ,latency int
    ,latencythreshold int
    ,agentnotrunning int
    ,agentnotrunningthreshold int
    ,timetoexpiration int
    ,expirationthreshold int            
    ,last_distsync datetime
    ,distribution_agentname sysname  null
    ,mergeagentname sysname null
    ,mergesubscriptionfriendlyname sysname null
    ,mergeagentlocation sysname null
    ,mergeconectiontype int
    ,mergePerformance int null
    ,mergerunspeed float null 
    ,mergerunduration int null
    ,monitorranking int       
    ,distributionagentjobid  binary(16) null
    ,mergeagentjobid binary(16) null
    ,distributionagentid int null
    ,distributionagentprofileid int null
    ,mergeagentid int null
    ,mergeagentprofileid int null
    ,logreaderagentname sysname null           
    ,publisher sysname null           
    DECLARE @Publications table
    Id INT IDENTITY ,
    Publication VARCHAR (MAX )
    SET NOCOUNT ON;
    INSERT INTO @Publications (Publication)
    SELECT Name FROM sysmergepublications
    SET NOCOUNT OFF;
    SET @i =  (SELECT MIN (Id) FROM @Publications);
    SET @Lenght = (SELECT COUNT (*) FROM @Publications);
    THIS IS THE PARTE THAT I HAVE MENTIONED BELOW..
    EXECUTE distribution.dbo.sp_replmonitorhelpsubscription 
    @publication = null,
    @publisher =  null,
    @publisher_db =  null,
    @publication_type = 0
    YOU HAVE TO EXECUTED LONELY
    WHILE (@i <= @Lenght)
    BEGIN
    SELECT @Publication = Publication
    FROM @Publications WHERE Id = @i;
    BEGIN TRY
    BEGIN TRANSACTION
    SET NOCOUNT ON;
    INSERT @ReplicationMonitor
    EXECUTE distribution.dbo.sp_replmonitorhelpsubscription 
    @publication = @Publication,
    @publisher =  @Server,
    @publisher_db = @Database ,
    @publication_type = NULL
    SET NOCOUNT OFF;
    COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
    ROLLBACK TRANSACTION;
    PRINT ERROR_MESSAGE(); 
    END CATCH
    SET @i = @i + 1;
    END;
    SELECT * FROM @ReplicationMonitor
    SET NOCOUNT OFF;
    NOTE: MAY BE IN YOUR CODE THE FIRST OUTPUT EXECUTION CAUSE A PROBLEM, BUT THIS RESOLVE MY ISSUE, I KNOW THAT IS NOT THE BEST MANNER TO PERFORM THIS, FOR I WANT TO BE CLEAR THAT IN MY CASE IT WORKED !
    You can try this solution with your own tables or executing another system procedure to test this.

  • Please send me some good links on System Function Calls

    Hi,
    I want to know more about System Function calls. Please send me some good links on the same.
    Eg : CALL 'C_DIR_READ_NEXT'
          ID 'TYPE'   FIELD file-type
          ID 'NAME'   FIELD file-name
          ID 'LEN'    FIELD file-len
          ID 'OWNER'  FIELD file-owner
          ID 'MTIME'  FIELD file-mtime
          ID 'MODE'   FIELD file-mode
          ID 'ERRNO'  FIELD file-errno
          ID 'ERRMSG' FIELD file-errmsg.
    Rgds,
    Raghavendra.

    Hi,
    <u><b>CALL - Call a System Function:</b></u>
    <b>Note</b>
    This statement is for internal use only.
    It cannot be used in application programs.
    As of Release 6.20, you should use Kernel Methods instead of system functions.
    <b>Syntax</b>
    CALL cfunc.
    Addition:
    ... ID id1 FIELD f1 ... ID idn FIELD fn
    <b>Effect</b>
    Calls the system function cfunc. The relevant function must exist in the file sapactab.h. If you change or recreate a function, you have to compile and link the SAP kernel again. For this, you need the C source code files.
    Normally, external programs should be called by RFC with CALL FUNCTION ... DESTINATION.
    <b>Addition</b>
    ... ID id1 FIELD f1 ... ID idn FIELD fn
    <b>Effect</b>
    Passes fields to the called program by reference. With "ID id1", you specify the name of a formal parameter, and with "FIELD f1" the relevant field from the ABAP/4 program. If a formal parameter expects an internal table, the latter is passed in the form "FIELD tab[]".
    Example
    DATA RESULT(8).
    CALL 'MULTIPLY' ID 'P1'  FIELD '9999'
                    ID 'P2'  FIELD '9999'
                    ID 'RES' FIELD RESULT.
    <b>Note</b>
    With some critical C functions, the system automatically performs an authorization check. If the user does not have the appropriate authorization, a runtime error occurs. You can check the authorization with the function module AUTHORITY_CHECK_C_FUNCTION.
    <b>Exceptions</b>
    Non-Catchable Exceptions
    Cause: You do not have the authorization to call this C function.
    Runtime Error: CALL_C_FUNCTION_NO_AUTHORITY
    Cause: The system function specified is unknown.
    Runtime Error: CALL_C_FUNCTION_NOT_FOUND
    Cause: The system function SYSTEM is deactivated (in CALL 'SYSTEM')
    Runtime Error: CALL_SYSTEM_DISABLED
    Regards,
    Bhaskar

  • Can anyone please tell me some basic infomation about Master data?

    Can anyone please tell me some basic infomation about Master data like
    1)The history of master data
    2) Why it is so critical
    3) What the advantages of it
    4) What is the future of master data
    Any inputs in this regard will be very helpful
    Thanks in advance

    Hi Gowri,
    Master data is backbone of any business software.It helps us to do transaction.
    If you go to any ATM and do some transaction,you get a monthly statement.This monthly statement contains your address details and your transaction details.
    So your address details and your account is like master data which is not changed so frequently but your transactions keep on happening on regular basis on your account and name.So your name and account are your master data which is set up once and donot change so frequently.
    Similary if you create a Purchase order in SAP system.You need Material master and vendor master.The material master contains material details and vendor master contains vendor details and using that you create PO which is a transactional data which keep on happening for a particular vendor & material combination on regular basis.
    So we set up master data once and make changes to these only when needed and record transaction against that.
    So in first case your banking details which you enter while opening account is your master data and in next case Material Master and vendor master is master data which set up mostly once.
    There are  three types of data in SAP system
    1. Organizational level data (ICICI Bank and Branch)
    2. Master data (Your User data while opening account)
    3. Transactional data (Your Regular transaction).
    I hope ,you are clear on this by now.
    There is a SAP software in Netweaver Stack now called MDM (Master data management) which will help to manage master data.
    regards,Nishant
    Please reward points if this helps.
    Message was edited by:
            Nishant Rajan

  • Please tell me some real time issues faced by u in SCRIPTS

    please tell me some real time issues faced by u in ur experience

    First understand SAP scripts are client dependent..changes automatically not reflects in all development client once it is change in once client.
    We mostly see alignment issue in SAP script it is mostly because of printer settings etc...
    Also we may have few problems when printing unicode characters.. for printing double digits characters... like Japanese, chinese, korean etc.. we should have a printer with unicode enabled..
    Regards,
    SaiRam

  • Please recommend me some good mailing list about oracle

    please recommend me some good mailing list about oracle
    thanks!
    null

    binghao (guest) wrote:
    : pleaes recommened me some good mailing list about oracle
    : thanks!
    I have seen a list of Oracle mailing lists at the Database
    Domain website which is at www.dbdomain.com I think. I think it
    used to me the www.oramag.com site. If you come across any good
    ones let me know. Good Luck
    Thomas Morgan
    null

  • Exec.State shows VI is "BAD", but VI is "GOOD"

    Any reasons why EXEC.STATE would indicate a "BAD" VI, but when opening the VI manually, it runs without a problem? I'm simply opening an App reference then the VI reference (both without error), then using the EXEC.STATE property. It SHOULD show "IDLE" when first loaded (until I use the RUN VI method). (This was something that used to work, but has suddenly changed in it's behaviour).
    BillM
    “A child of five could understand this. Send someone to fetch a child of five.”
    ― Groucho Marx

    I just had another thought. I bet that you have a duplicated VI filename. One version of the VI has a connector pane that is linked to the dynamic VI. A second version has the same name, but a different connector pane, and is used in the VI that calls the dynamic VI. As long as you open the dynamic VI by itself it links to the correct one. Open it dynamically and the dynamic VI finds the version that is already loaded into memory by the caller VI, which breaks the dynamic VI.
    Mike...
    Message Edited by mikeporter on 07-01-2007 06:30 PM
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Please tell me some important tcodes

    hi,
    i am very new to MM .i would like know some important tcode.
    Can you please tell me few tcodes in mm and their purposes.
    Thanks in advance
    Regards
    Naresh.

    Pls check Links
    http://www.sap-img.com/materials/list-of-sap-mm-transaction-codes.htm
    http://www.sap-img.com/materials/important-sap-mm-tcodes-1.htm
    http://www.sap-img.com/materials/important-sap-mm-tcodes-2.htm

  • Please reply with some good news... :(

    Please can someone help me....
    For the past few days my iphone5 has been nothing but a nightmare..
    Its 3months old I got as a replacement phone from Apple.
    It started off by going through the battery quicker than usual.....
    Then when I tried to charge it, it would charge to 5% then stop charging, I had to unplug the
    charger and reconnect in hopes I will get a full charge.
    Then all of a sudden it doesnt wanna charge, I used 3 different chargers that is of my sister #5
    My phone is now Offically dead and wont show the charging icon to show its charging...
    Ive done a hard reset with the home and off button and also with it charging and also gave the mute button a play...
    Im not sure what to do if anyone has any advise please do so and help me out here guys...
    CHEERS

    Apple products usually have a one year warranty, I would take it to Apple Store.

  • Hi. In simple language, can you please tell me the best way to protect my important and numerous files - music, images and docs - from being lost; in the event the computer crashes and data is irretrievable?

    I have a lot of photos and music, plus important personal files. In simple terms, can you recommend how I should go about backing these up and ensuring they are not lost through some computer malfunction?
    I need to understand the uses and merits of iCloud, Time Machine and on/off site external drives. I don't really want to invest money, time or new external hardware to achieve this. It can't be too labour intensive, either.
    I have an external drive, which I last backed up perhaps two years ago. It is old, it requires wiring, and it sits next to to the desktop, so would be useless in case of fire (god forbid), say.
    At the same time, I am concerned about cloud storage, and putting personal info and files into anonymous server farms, and the hands of anonymous organisations/people.
    Call me a luddite, but I suspect these are fairly standard concerns, and I can find simple answers with a simple Google search.
    Thanks in advance for your help.

    This is what Apple has to say:
    Report on Government Information Requests
    "... our business does not depend on collecting personal data. We have no interest in amassing personal information about our customers."
    This one concerns iOS, but its approach to privacy is the same:
    http://images.apple.com/ipad/business/docs/iOS_Security_Feb14.pdf
    A couple stories about one Google alternative:
    DuckDuckGo: the plucky upstart taking on Google with secure searches
    DuckDuckGo: The privacy search ruffling Google's feathers
    NSA scandal delivers record numbers of internet users to DuckDuckGo
    Why Traffic To These Google Alternatives Is Soaring
    One of several concerns about Google Chrome, for instance:
    Chrome Bugs Allow Sites to Listen to Your Private Conversations
    Google's Business Model: YOU Are the Product
    "You are not a Google customer. You are a Google product."
    Those aren't just anyone's worthless opinions. Those are also the exact words of a federal magistrate dismissing a case regarding privacy intrusion involving the plaintiff's Android phone:
    "... With little or no revenue from its users, Google still manages to turn a healthy profit by selling advertisements within its products that rely in substantial part on users’ personal identification information (“PII”). As some before have observed, in this model, the users are the real product."
    I understand you didn't ask primarily about Google, but you expressed the very understandable desire for privacy, yet don't seem to mind using Google for search. Those aren't reconcilable sentiments.

  • Can someone please tell me an easier way to split a clip?

    I just recently upgraded to iLife '09. I really miss the old iMovie where all you had to do to split a clip was press command-T, and then delete the part you don't want. Now it has the yellow box that you drag using the mouse and it just is not working for me. Is there a way to go back to the command-T method or just something easier than using the mouse? I'm more of a keyboard person and I like to use the mouse as little as possible.

    I'm just learning iMovie '09 (was still using iMovie HD) but I believe that the "Split Clip" command only works in a project, not an event. I found this post and it kinda helped. It appears you basically have to delete a frame and send rejected to trash to make one clip in an event 2 separate clips.
    http://discussions.apple.com/thread.jspa?messageID=8889359&#8889359

  • Please tell me some information about gmail

    hi, everybody. I'm a long time OSX user but I never used the "mail." Now, I want to try mail with my gmail account but I found it's not that easy. First of all, what type of account is the gmail? IMAP, POP, or Exchange? Next, what is incoming mail server and outgoing mail server? Thanks so much!

    Gmail offers POP, which means you can use Mail.app like a regular ISP account. If you need an invite to GMail email me at the address on http://Gnarlodious.com/
    Once yiou have a Gmail address you need to enable POP (which includes SMTP). There is a help link on the GMail page that allows you to enable POP and other features.
    Once that is turned on, you need to set up the Mail.app for downloading your mail (and uploading). There are excellent instruction pages on Gmail, which I believe someone else gave you.

  • Hi, Please tell me the esiest way to order ink. Thanks

    It's time for me to order ink, what is the easiest way to do that? Thanks

    BGorman wrote:
    It's time for me to order ink, what is the easiest way to do that? Thanks
    Hi BGorman, your best bet is to go to SureSupply. Enter your printer model and it'll show the compatible cartridges...
    https://h30042.www3.hp.com/SureSupply/
    Hope this helps
    Ciara
    Although I am an HP employee, I am speaking for myself and not for HP.
    Twitter: @Ciara_B_HP

  • Please tell me some link of good advance practice code on JTable&JTree

    Hi, I am learning swing and developing a project .I read the sun document .Can u tell me some good link of learning the advace JTree&JTable . I want more expose in this area.
    Thanks in advance,
    anum

    [url http://java.sun.com/docs/books/tutorial/uiswing/TOC.html]The Swing Tutorial

  • Please tell me some conversion tools to generate java help

    hello,
    I am doing some project of migration, and I need some tools to convert from windows help file (chm) to java help file.
    Anyone has some experience of that?
    If not possible, what's the fastest way to do the conversion?
    Thanks

    Hello,
    You don't mention what format the source files are in, so I'm assuming that you only have access to the actual .chm files and not whatever those were created from. Given that, you'll need a tool that is capable of backward converting Help output into some source format, and then converting that to JavaHelp. I don't know of anything that would convert directly from .chm to JavaHelp.
    I believe that RoboHelp is capable of taking Window Help output and converting it backwards to source, and it is also supports JavaHelp, so this would be one tool to investigate.
    HelpBreeze is another tool that supports both formats and is also a lot cheaper that RoboHelp.
    I apologize for not having first-hand experience with either of these. We currently use a CMS tool, AuthorIT, to single source publish to JavaHelp and other outputs.

Maybe you are looking for

  • ILife 08 iMovieLack of Video Effects

    I loaded iLife 08 and like many of the features but it is a big step backwards especially in iMovie. A few issues are: When finished iMovie, the requirement is to export the movie to desktop and then import to iDVD 08. This seems to be the only way t

  • How to switch the control from one browser to another browser for automating the application in VBScript?

    I am automating a web application which is opening a another model Pop up browser. But the control remains in the first browser itself. I want to switch the control to the recently opened popup browser. Please provide me the solution that how it coul

  • How can I get cross fade/dissolve of both audio and video?

    I want to centre the coss fade/dissolve transition on the clip boundary.  I can do this with the video cross dissolve but not the audio cross fade - for the audio, the Alignment facility in the Edit transition is greyed out and the transition can onl

  • Password prompt when I connect

    I just setup my wireless router and I setup a key to connect but it only asked me once for the password when I hit the connect option. Now every time I hit connect it does not ask me for the password I set. What do I have to do for every time I hit t

  • Doubt in idoc tpssht01

    Hi all, Can any one tell me the mandatory fields to be filled in idoc(tpssht01). Actually now am facing an error delivery no. not relevant for shipment while receiving as inbound. How to resolve it. Thanks in advance, Sakthi