读书人

插入多行数据解决方案

发布时间: 2012-01-19 00:22:28 作者: rapoo

插入多行数据
表1 Records
id objectid cost unitid dates
1 a 900.8 xx 2007-1-1
2 a 800.8 xx 2007-1-2
3 b 700.7 xx 2007-1-3
4 b 600.8 xx 2007-1-7
表2 budget
id objectid unit money
要将表1中的 objectid unitid sum(cost)按objectid分组插入到表2中

string strSQL = "insert into budget (objectid,unit_id,money) select Records.objectid,Records.unitid,(sum(Records.cost)) as mon from Records where Recordes.unitid= 'xx ' group by Records.objectid ";
这个语句正确吗?为什么不能插入到budget中.


[解决办法]
insert into budget(objectid,unitid,money) select objectid,unitid,sum(cost) as money from Records group by objectid,unitid

读书人网 >SQL Server

热点推荐