怎么批量增加数据库两张表里不同字段不同内容的数据

感恩1. mysql数据库,sql语句查询不到表里数据的对应的数据结果,代码无报错
2. c++ 中有什么方法可以往数据库里批量插入数据?数据库是sqlserver

如果写程序就很简单了,先写个程序把所有部门名称查询出来,放到一个list里面
list[0]=部门0
list[1]=部门1
list[2]=部门2
...
再写个SQL来循环判断有没有该部门名字的用户名
for 循环list里面的元素
select count(*) from opu_om_user where opu_om_user.userid=opu_om_user_org.userid and opu_om_user_org.orgid=opu_om_org.orgid and opu_om_org=list[i]
如果count()结果=0插入,否则continue


insert  into  opu_om_user  (name )
select   z.orgname  from  opu_om_org z where not   exists
    ( select   1 from  opu_om_org a inner   join  opu_om_user_org b  on a.orgid=b.orgid inner  join  opu_om_user c on  b.userid=c.userid where a.orgname = c.username and z.orgname=c.username );
insert  into  opu_om_user_org(userid ,orgid)
select  z.userid,y.orgid from opu_om_user  z  inner  join   opu_om_org  y on z.username=y.orgname
where not exists( select   1 from  opu_om_org a inner   join  opu_om_user_org b  on a.orgid=b.orgid inner  join  opu_om_user c on  b.userid=c.userid where a.orgname = c.username and z.userid=c.userid and  y.orgid=a.orgid);