MS SQL update set select

有张表a,已经有数据

再有张表b,也已查询出数据

两张表有外键关联

需求如下:

       更新表a中的某个字段,这个字段要加上(都是int型的数据)对应表b中的数据作为更新的最终数据

update #libList set actiCount=ISNULL(actiCount,0)+ ISNULL(total,0)  from  #libList left join T on #libList.id= T.libraryid

"total"中是T表中的字段,isnull表示如果没有关联到,则使用0

posted on 2014-10-22 09:58  LitDev  阅读(964)  评论(0编辑  收藏  举报