0

I created a temp table which will store data returned from a stored procedure. Apparently, when I try to execute this, 'INSERT_EXEC can't be nested' error is shown.

Msg 8164, Level 16, State 1, Procedure sp_kbbl_WachLista_Priprema, Line 24 An INSERT EXEC statement cannot be nested

Here is the code sample...

CREATE TABLE #WL_Klijenti ( [Datum_Izvjestaja] varchar(10), [Aplikacija] 
varchar(10), [OJK] varchar(12),
[OJ_Nova] varchar(50), [MBR] varchar(20), [Sifra_Firme] int, 
[Naziv_Komitenta] varchar(256), [Mjesto] varchar(30),
[Segmentacija] varchar(80), [Partija] varchar(20), 
[Odobreni_Iznos_Limit_BAM] decimal(16,2), 
)

INSERT INTO #WL_Klijenti
  EXEC sp_kbbl_WachLista_Priprema '2017.09.30', '2017.09.30', 0

 DROP TABLE #WL_Klijenti
 SELECT * FROM #WL_Klijenti

What does this mean? How can I avoid it and what are possible solutions to this?

EDIT:

Sunil, lines 15-30

     IF NOT EXISTS (SELECT TOP 1 * FROM dbo.KBBL_Plasmani_Portfolio WHERE 
     Datum_Izvjestaja = @Datum_Izvjestaja)    
      BEGIN    
      RAISERROR ('For the particular date, there is no data in 
      KBBL_Plasmani_Portfolio!', 16, 1)    
      GOTO kraj    
         END     



    CREATE TABLE #UkupneObaveze (PartnerId int,SmanjenjePoslovnihPrihoda 
    NUMERIC(18,2),RastUkupnihObaveza NUMERIC(18,2))
      INSERT INTO #UkupneObaveze
    EXEC kbbl_sp_PoslovniPrihodi_UkupneObavezeSkraceni @Datum_Bilansa


     SELECT p.Partija, MIN(dknizenja) AS Datum_Pustanja_Plasmana
        INTO #Plasman

Question edit:

How can I create table valued function and pass it inside the first query I posted here. My idea is to execute the procedure from TVF...

unknown
  • 461
  • 9
  • 23
  • Please add code from SP: sp_kbbl_WachLista_Priprema – Sunil Jan 08 '18 at 09:30
  • Sunil, procedure is pretty big, if you think it will help you I will upload it and share the link. – unknown Jan 08 '18 at 09:31
  • Add Lines 15 to 30. The error is on Line 24 – Sunil Jan 08 '18 at 09:32
  • 1
    Possible duplicate of [Errors: "INSERT EXEC statement cannot be nested." and "Cannot use the ROLLBACK statement within an INSERT-EXEC statement." How to solve this?](https://stackoverflow.com/questions/3795263/errors-insert-exec-statement-cannot-be-nested-and-cannot-use-the-rollback-s) – Jayasurya Satheesh Jan 08 '18 at 09:33
  • Sunil, take a look at the edit. – unknown Jan 08 '18 at 09:52

0 Answers0