我想将表k_day里的exception(int型)字段求和后插入k_month表的lost字段select a0188,sum(isnull(k_day.exception,0)) as lose into k_month from k_day group by a0188这样写可以不?PS:a0188是表的唯一标识ID,类似于人员表中的姓名字段。

解决方案 »

  1.   

    参考:
    declare @total int
    SET @total = select SUM(price) from k_day
    update k_month set lost=@total
      

  2.   

    如果表k_month已经存在的话这样不行的吧?
      

  3.   

    你这是要在存储过程中执行的SQL还是VC程序中??
      

  4.   

    不过你用了group by,select出来有多条记录,则应该用游标对每条记录进行循环处理。。