哈哈,好的告訴我email我來發給你

解决方案 »

  1.   

    比如一個BOM表,我現在要進行此BOM表所有節點的拷貝
    每個節點有BOM編號和自身的節點編號,以及上級節點編號
    我的方法是每拷貝一個節點就將源節點的子節點拷貝並且把上級節點編號修改成剛拷貝生成的那個節點的編號,我在程序裡面處理的,效率不理想
    所以想寫個存儲過程
      

  2.   

    請給出相應的BOM結構,我好做分析
      

  3.   

    好象并没有说清楚
    1. COPY的节点允许放在父节点下吗还是处于根的位置?
    2. 如果新节点没有父节点,pid如何处理?
    3. “傳入一個整形數組”其中數組的的含义是什么?代表多个被复制的ID还是...
    4. 传入的参数是什么作用?新节点的父ID还是被复制的ID?
      

  4.   

    你传入的是一些ID的集合
    是否只要返回 ID, P_ID的一个集合?
      

  5.   

    不返回任何東西,實際執行了就夠了至於 Brunhild() 說的
    1.本來是在什麼節點下面的就還是按照同樣的結構拷貝
    2.=0
    3.比如我想拷貝一些節點int[] ids = new int[]{1,5,6};那麼就得把ID為1,5,6的節點和子節點進行拷貝
    4. see point above
      

  6.   

    傳入bom編號,找到其根節點,然后找該節點的下級基點,并且插入一個臨時表。
    最后從該臨時表取數據即可。
      

  7.   

    我要是會就不問了大哥
    你直接給我個代碼看看
    比如(執行前,節點內容如下)
    id=10 的pID = 1
    id=11 的pID = 3
    id=12 的pID = 5
    id=13 的pID = 6
    id=14 的pID = 13
    id=15 的pID = 10
    那麼當傳入"1,3,5,6"後,需要構建一批新節點
    摹擬生成的新節點(執行後,源節點ID  這一欄不必要,是我為了對照才寫上去的)
    源節點ID      ID       pID
    1             20        0     (因為,1,3,5,6本來的pID=0)
    3             21        0
    5             22        0
    6             23        0
    10            24        20
    11            25        21
    12            26        22
    13            27        23
    14            28        27
    15            29        24
      

  8.   

    暈,我寫了一個,給我email我發給你
      

  9.   

    問題已經解決了
    說實話,存儲過程也很麻煩的
    畢竟是自動編號
    所以就添加了一個字段oid
    記錄下源節點編號
    然後提取出源節點集和目標節點集(已經生成的新的)
    然後對照目標節點OID的值去原來的節點集合中搜對應的節點,找到pid再到目標節點集裡面找
    oid=源pid的節點,得到其id存到目標節點的pid裡面去即可
    因為所有操作都在內存中操作的,提取數據一次回存數據一次,總共兩次和數據庫通訊
    效率鍋的去
      

  10.   

    /*--复制树形结点 将一个结点下的所有子结点复制到另一个结点下--*/
    --创建数据测试环境
    create table #tb(id int identity(1,1),parentid int,name varchar(10))
    insert into #tb
    select 0,'中国'
    union all select 1,'广东'
    union all select 1,'广西'
    union all select 1,'四川'
    union all select 2,'广州'
    union all select 2,'佛山'
    union all select 2,'东莞'
    union all select 5,'越秀区'
    union all select 5,'海珠区'
    union all select 5,'芳村'
    union all select 6,'禅城区'
    union all select 6,'南海区'
    union all select 11,'石湾'
    go--创建复制的存储过程
    create proc p_copy
    @s_id int, --复制该项下的所有子项
    @d_id int --复制到此项下
    as
    declare @nid int,@oid int,@name varchar(10)
    select id,name into #temp from #tb where parentid=@s_id
    while exists(select 1 from #temp)
    begin
    select @oid=id,@name=name from #temp
    insert into #tb values(@d_id,@name)
    set @nid=@@identity
    exec p_copy @oid,@nid
    delete from #temp where id=@oid
    end
    go--测试
    exec p_copy 2,3--显示处理结果
    select * from #tbgo
    --删除数据测试环境
    drop proc p_copy
    drop table #tb
      

  11.   

    如果照你的要求,要再加多一个存储过程.就是下面的例子:/*--复制树形结点 复制指定结点及其下面的子结点--*/
    --创建数据测试环境
    create table #tb(id int identity(1,1),parentid int,name varchar(10))
    insert into #tb
    select 0,'中国'
    union all select 1,'广东'
    union all select 1,'广西'
    union all select 1,'四川'
    union all select 2,'广州'
    union all select 2,'佛山'
    union all select 2,'东莞'
    union all select 5,'越秀区'
    union all select 5,'海珠区'
    union all select 5,'芳村'
    union all select 6,'禅城区'
    union all select 6,'南海区'
    union all select 11,'石湾'go
    --创建复制的存储过程
    create proc p_copy
    @s_id int, --复制该项下的所有子项
    @d_id int, --复制到此项下
    @new_id int --新增加项的开始编号
    as
    declare @nid int,@oid int,@name varchar(10)
    select id,name into #temp from #tb where parentid=@s_id and id<@new_id
    while exists(select 1 from #temp)
    begin
    select @oid=id,@name=name from #temp
    insert into #tb values(@d_id,@name)
    set @nid=@@identity
    exec p_copy @oid,@nid,@new_id
    delete from #temp where id=@oid
    end
    go--创建批量复制的存储过程
    create proc p_copystr
    @s_id varchar(8000) --要复制项的列表,用逗号分隔
    as
    declare @nid int,@oid int,@name varchar(10)
    set @s_id=','+@s_id+','
    select id,name into #temp from #tb
    where charindex(','+cast(id as varchar)+',', @s_id)>0
    while exists(select 1 from #temp)
    begin
    select @oid=id,@name=name from #temp
    insert into #tb values(@oid,@name)
    set @nid=@@identity
    print @oid
    print @nid
    exec p_copy @oid,@nid,@nid
    delete from #temp where id=@oid
    end
    go--测试
    exec p_copystr '5,6'--显示处理结果
    select * from #tbgo
    --删除数据测试环境
    drop proc p_copystr,p_copy
    drop table #tb