table1:  字段为
ID1,ID2,ID3,ID4table2:  字段为
ID,Nameselect b.name,c.name,d.name,e.name from table1 a left join table2 b 
on a.id1=b.id
left join table2 c
on c.id2=b.id
left join table2 d
on d.id3=b.id
left join table2 e
on e.id4=b.id

解决方案 »

  1.   

    update table1
    set table1.id1=table2.name
    from table2
    where table1.id1=table2.id
    不行就建立一个新表吧
    insert into newtable(id1_name)
    select b.name
    from table1 as a,
         table2 as b
    where a.id1=b.id
      

  2.   

    select (case a.ID1 when b.ID then b.name else null end) as ID1_Name,
           (case a.ID1 when b.ID then b.name else null end) as ID2_Name,
           (case a.ID1 when b.ID then b.name else null end) as ID3_Name,
           (case a.ID1 when b.ID then b.name else null end) as ID4_Name 
    from table1 a,table2 b不过这样会出现很多的空数据
      

  3.   

    查询:select
    (select name from table1 where id=table1.id1) ID1_Name,
    (select name from table1 where id=table1.id2) ID2_Name,
    (select name from table1 where id=table1.id3) ID3_Name,
    (select name from table1 where id=table1.id4) ID4_Name
    from table1
      

  4.   

    select a.name as ID1_Name
          ,b.name ad ID2_Nametable1:  字段为
    ID1,ID2,ID3,ID4table2:  字段为
    ID,Name
      

  5.   

    刚才不小心发错了 抱歉!
    select a.name as ID1_Name
          ,b.name as ID2_Name
          ,c.name as ID3_Name
          ,d.name as IDs_Name
    from table1 left join table2 a on a.id=id1
    left join table2 b on a.id=id2
    left join table2 c on a.id=id3
    left join table2 d on a.id=id4
      

  6.   

    Create Functinon searchname @Id
    return Varchar(200)
    as 
     
    Return (select name From table2 where id=@id)goselect id1_name=searchname (id1),
           id1_name=searchname (id2),
           id1_name=searchname (id3),
           id1_name=searchname (id4)
    From table1
      

  7.   

    谢谢各位支持帮助 CrazyFor(蚂蚁)的方法最好,wyb0026(小小) 和他是一样的.
     psxfghost(哈哈) 的方法挺有创意,效果不好,把ID顺序打乱每一条记录的对应列的名字和顺序都改变了pengdali(大力 V2.0) 的方法不可行,因为子查询里有多个记录的话,查询失败 lilu207(lilu) 的方法我也考虑过,建表不方便还是CrazyFor方法最好,谢谢了.