http://expert.csdn.net/Expert/topic/1375/1375432.xml?temp=.8570978

解决方案 »

  1.   

    select *,(select 列3 from 表 where 列1=tem.列1) 列4 from 表 tem
      

  2.   

    select *,(select 列3 from yourtable where 列1=列3) 列4 into #t from yourtable
    select * from #t
      

  3.   

    最好不要写代码,用1个SQL实现,谢谢各位大哥了
      

  4.   

    设表为 table
    字段为 F1       F2                F3   F4如下即可:
    update table set F4 = F3
    while @@Rowcount > 0
    begin
       update a set F4 = b.F3 from table a
           join table b on a.F4 = b.F1
           where a.F4 not in ('0','1')
    end
      

  5.   

    txlicenhe(不做技术高手)您好,您的做法好象结果不正确,不知道我有没有说清楚我的意思,能否用1个SQL语句,谢谢各位大哥
      

  6.   

    select *,case (select 列3 from yourtable where 列1=列3) 列4 when 1 then 1 else  
    (select 列3 from yourtable where 列1=列3) 列4  end into #t from yourtable
    select * from #t
      

  7.   

    1:嵌套的树状结构一条语句不可能搞定,必须循环。
    2:我觉得没有比如下语句更简单的了。
    Select F1,F2,F3,F3 as F4 into #tmp from table
    while @@Rowcount > 0
    begin
       update a set F4 = b.F3 from #tmp a
           join #tmp b on a.F4 = b.F1
           where a.F4 not in ('0','1')
    end
    Select * from #tmp
      

  8.   

    select ok.s aa,ok.t bb,ok.u cc,
    case when not ok.b is null then ok.b
    when not ok.e is null then ok.e
    when not ok.h is null then ok.h
    when not ok.k is null then ok.k
    when not ok.n is null then ok.n
    when not ok.q is null then ok.q
    else ok.t
    end
    as dd
    --,ok.*
    from
    (
    select ppppp.*,g.a s,g.总公司 t,g.b u
        from
    (select pppp.* ,f.a p,f.总公司 q,f.b r
        from
    (select ppp.*,e.a m,e.总公司 n,e.b o 
        from
    (select pp.*,d.a j,d.总公司 k,d.b l 
        from  (select p.*,
            c.a g,c.总公司 h,c.b i 
                    from (select a.a a,a.总公司 b,a.b c,
          b.a d,b.总公司 e,b.b f
                  from chen a
          right join chen b on a.a=b.b)
                    as p
            right join chen c on p.d=c.b)
        as pp
        right join chen as d on d.b=pp.g)
        as ppp
        right join chen as e on e.b=ppp.j)
        as pppp 
        right join chen as f on f.b=pppp.m)
        as ppppp 
        right join chen as g on g.b=ppppp.p
    ) as ok
    order by aa,bb,cc要这么麻烦吗??