首页 > 代码库 > MS SQL update set select

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

MS SQL update set select