求助大虾:
更新一个数据表里某字段的值为该字段原有数据+新数据,用一个sql语句该怎么写了?谢绝类似的方法:从表里读出这个字段的数据,然后在程序进行累加,最后才更新上去。

解决方案 »

  1.   

    具体数据?及希望的结果数据格式?update a set x=(select sum(x) from tb where id<=a.id) from tb a这样?
      

  2.   


    declare @a int
    update 表 set @a = @a + 字段
      

  3.   


    update 表 set 更新字段= 更新字段+(select sum(字段)from 表2 group by 排序字段)
    再复杂的就用动态语句更新。
    请提出具体要求!
      

  4.   

    是这样吧 update 表 set 列=列+新数据
      

  5.   

    update 表1 set 列=表1.列+表2.新数据
    from 表1
    inner join 表2
    on 表1.id=表2.id
      

  6.   

    应该是这样吧
    update a set x=(select sum(x) from tb where id <=a.id) from tb a 
      

  7.   

    declare @a int
    update 表 set @a = @a + 字段
      

  8.   

    开发环境为:vs2008c#;数据库为sql server 2005
    数据字段c1类型为nchar,更新满足某一要求的行中c1的值为c1原有值+新值,新值来源于程序。本人对sql语法不太了解,感觉2楼的代码可行,但还没去验证。
      

  9.   


    declare @a int
    update 表 set @a = @a + 字段