CREATE TABLE #test(colAssetID int not NULL)
INSERT INTO #test
EXEC B_Create 145, 'Name_T', 'Test',2Error: An INSERT EXEC statement cannot be nested
B_Create 是个返回SELECT 结果的存储过程,不是return返回,也不是output返回,他会返回一行一列的一个值.我之前用过上面的方法得到SELECT结果,但用在这个比较复杂的B_Create上会就有上面的错误,请问有什么别的方法得到SELECT的返回值吗?在线等答案,马上给分

解决方案 »

  1.   

    要看你B_Create返回的是不是合符的集合。
      

  2.   


    use dbx
    go
    create procedure up_t
    as
    begin
    select 1 union all 
    select 2 union all
    select 3 union all
    select 4
    endgocreate table #t
    (
    id int primary key identity(1,1)
    ,c int
    )
    goinsert into #t exec up_tselect * from #tdrop table #t
      

  3.   

    create proc B_Create
    (
    @i int,
    @o nvarchar(20),
    @p nvarchar(20),
    @q int
    )
    as
    begin
    select 1
    end
    CREATE TABLE #test(colAssetID int not NULL)
        INSERT into #test
        EXEC B_Create 145, 'Name_T', 'Test',2
      
        
    select * from #test /*
    colAssetID
    -----------
    1
    */  
    drop table #test没有问题啊
      

  4.   

    如果返回正确是没有问题的
    我测试通过CREATE TABLE kk(a INT ,b DECIMAL(10) )                    -- 
    INSERT INTO kk                     
    exec dbo.PROC_StaticNeedMaterial 43493   fldID                fldProductCode  fldMaterialCode fldNeedQuantity                         fldLostQuantity
    -------------------- --------------- --------------- --------------------------------------- ---------------------------------------
    1                    P101            15772           10.00000000                             2.00000000
    3                    P102            15772           15.00000000                             3.00000000
    4                    P103            3748            12.00000000                             4.00000000
    5                    P104            48926           13.00000000                             2.00000000
    6                    P105            48926           12.00000000                             2.00000000
    7                    P106            48926           24.00000000                             5.00000000
    938                  43493           10035           10.00000000                             0.05000000
    939                  43493           10042           23.00000000                             0.11500000
    940                  43493           10050           5.00000000                              0.05000000
    941                  43493           10052           1.00000000                              0.00500000(10 row(s) affected)
      

  5.   

    EXEC B_Create 145, 'Name_T', 'Test',2
    这个结果是什么?是否满足你那个临时表?
      

  6.   


    alter proc B_Create
    (
    @i int,
    @o nvarchar(20),
    @p nvarchar(20),
    @q int
    )
    as
    begin
    EXEC('select 1 union all select 2')
    end
    CREATE TABLE #test(colAssetID int not NULL)
        INSERT into #test
        EXEC B_Create 145, 'Name_T', 'Test',2
      
        
    select * from #test /*
    colAssetID
    -----------
    1
    2(2 行受影响)*/  
    drop table #test可能是你存储过程的问题
      

  7.   

    Error: An INSERT EXEC statement cannot be nested==================
    晕倒,你存储过程嵌套了,出现问题,修改存储过程。
      

  8.   


    这个错误提示还不够明白吗?INSERT EXEC 不能嵌套说明: 存储过程 B_Create 返回的结果集,也是通过 insert exec 另一个存储过程 生成的

    这种嵌套是不允许的
      

  9.   

    LZ为何把insert into写入存储过程中。
    你的存储过程有问题。
      

  10.   

    这个存储过程不能发啊,会违反规定的,里面是有insert操作
      

  11.   

    晕,SP有insert to就是有问题!!