将查询出来的数据插入到表1中的SQL语句:insert into 表1 select 字段列表 from 表(n) where 条件

语法:insert into 表1    select 字段列表 from 表(n) where 条件

相当于 复制和粘贴,  select 后加要复制的东西,insert into 粘贴到

注意:只要查询出来的字段列表与要插入的表的字段个数一致就可以

例子:将本月数据同步上月数据

思路:首先删除本月的数据,

     其次查出来上个月的数据,并插入到表(月报表8)中,插入时主表id为本月id(因为我要把本月的数据同步(替换)上月数据)

insertSql += @"    insert into [月报表Table8]
                               select  '{0}',名称,数量,签订信息化平台建设合同,重大危险源监测预警系统,安全风险分区管理系统,生产人员在岗在位管理系统,生产全流程管理系统,四大系统,计划六月份完成企业数,计划九月份完成企业数 from [月报表Table8] where 主表id='{1}'";

将查询出来的数据插入到表1中的SQL语句:insert into 表1 select 字段列表 from 表(n) where 条件

将查询出来的数据插入到表1中的SQL语句:insert into 表1 select 字段列表 from 表(n) where 条件