sql两张表关联更新字段
记录,推荐使用第三种,个人觉得比较好
--第一种写法,之前一直用,没有在意 UPDATE sr_t_TCodeUserReciveCfg SET fUserID=a.fUserID,fImportFlag=NULL FROM dbo.vw_userinfo AS a INNER JOIN dbo.sr_t_TCodeUserReciveCfg AS b ON a.sLoginName=b.fImportFlag WHERE b.fImportFlag IS NOT NULL --第二种写法,发现第一种写法有些不符合语法,这种比第一种好 UPDATE b SET fUserID=a.fUserID,fImportFlag=NULL FROM dbo.vw_userinfo AS a INNER JOIN dbo.sr_t_TCodeUserReciveCfg AS b ON a.sLoginName=b.fImportFlag WHERE b.fImportFlag IS NOT NULL --第三种写法,这种方法更加简洁,是不是??? UPDATE sr_t_TCodeUserReciveCfg SET fUserID=a.fUserID,fImportFlag=NULL FROM vw_userinfo a WHERE fImportFlag=a.sLoginName AND fImportFlag IS NOT NULL
慎于行,敏于思!GGGGGG