SELECT *
FROM [dbo].[t_ttgzb]
WHERE htbm = '595' 
SELECT *
FROM [dbo].[t_ttgzb]
WHERE htbm = '283'
我想让查询htbm(合同编码) = '595' 查询出来数据中的hyh(会员号)更新为查询htbm (合同编码)= '283'数据中的hyh(会员号),条件是htbm = '595' 中的xm(姓名)等于htbm = '283'中的xm(姓名),查询语句应该怎么写

解决方案 »

  1.   

    是查询还是更新,在执行以下语句前请做好备份
    update a
    set a.hyh=b.hyh
    from [dbo].[t_ttgzb] a,[dbo].[t_ttgzb] b
    where a.htbm = '595' and b.htbm = '283'
    and a.xm=b.xm
      
      

  2.   

    update a set hyh = b.hyh from [dbo].[t_ttgzb]
    a,[dbo].[t_ttgzb] b where a.htbm = '595' and b.htbm = '283' and a.xm = b.xm
      

  3.   

    update [t_ttgzb] hyh=b.hyh
    FROM [dbo].[t_ttgzb] as a inner join [dbo].[t_ttgzb] as b on a.xm=b.xm
    WHERE a.htbm = '595' and b.htbm='283'