当前位置:编程学习 > C#/ASP.NET >>

asp.net怎么实现数据库中同一表的两数相加

asp.net怎么实现数据库中同一表的两数相加,并写进数据库中 --------------------编程问答-------------------- UPDATE TABLE1 SET C1=C2+C3  --------------------编程问答-------------------- 两数据是在同一行数据中,还是? --------------------编程问答-------------------- 是不同行,两数相加之后结果在第三行出现
--------------------编程问答-------------------- 1楼这个就可以  
引用
UPDATE TABLE1 SET C1=C2+C3  
--------------------编程问答-------------------- 我觉得你应该把表结构发出来,至少让人知道,你要把哪两列相加放到哪里。 --------------------编程问答--------------------  select line from table where xxx  --你的第一行
 union all
  select line from table where xxx  --你的第二行
  union
 all select (select line from table where xxx )+(select line from table where xxx)  --第三行了

如果是int类型之类的还需要转型
convert(int ,xxxx )  --------------------编程问答-------------------- 可以使用DataTable实例化新行,然后计算添加行。 --------------------编程问答-------------------- 用加号相加。。。 --------------------编程问答-------------------- update table set c=(select sum((select c1 as c1 from table where 条件)+(select c2 as c2 from table where 条件)) from table where 条件) --------------------编程问答--------------------
引用 9 楼 ailiku1988 的回复:
update table set c=(select sum((select c1 as c1 from table where 条件)+(select c2 as c2 from table where 条件)) from table where 条件)


写错了
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,