update a set a.字段1=b.字段2 from 表1 a join 表2 b on a.id=b.id

解决方案 »

  1.   

    update table1 set table1.字段1=table2.字段2 
    from table2 where table1.id=table2.id
      

  2.   

    create table #参数表(id int,col1 char(10))
    go
    create table #数值表(id int,col2 char(10))
    goinsert into #数值表(id,col2)
    select 1,'1'
    union all
    select 2,'2'
    union all
    select 3,'3'insert into #参数表(id,col1)
    select 1,'one'
    union all
    select 3,'three'select * from #数值表update a set a.col2=b.col1 from #数值表 a join #参数表 b on a.id=b.id
    goselect * from #数值表drop table #数值表
    drop table #参数表
    go
    /*(所影响的行数为 3 行)
    (所影响的行数为 2 行)id          col2       
    ----------- ---------- 
    1           1         
    2           2         
    3           3         (所影响的行数为 3 行)
    (所影响的行数为 2 行)id          col2       
    ----------- ---------- 
    1           one       
    2           2         
    3           three     (所影响的行数为 3 行)
    */
      

  3.   

    update a set a.更新字段=b.参数字段 from 数值表 a inner join 参数表 b on a.字段=b.字段
    其中数值表中的字段与参数表中的值段相等的前提为两个表的字段为相对应的字段信息