以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]选择并复制记录问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=103845) |
-- 作者:lzzhx -- 发布时间:2017/7/18 14:53:00 -- [求助]选择并复制记录问题 请教老师: 有两个表:表A(10000条记录)和表B(2000条记录),主键均为 _Identify 表B中有一个字段“编号”,类型为整形,存放从表A复制记录时的表A的_Identify的值 当前主表是表B,在表B的主窗口中放置一个按钮(btn提取数据),点击按钮时,将表A的所有不在表B中的记录复制到表B中, 代码该怎么写?我下面的代码提示[查询超时已过期,未将对象引用到对象的实例],用消息框看ids的值是空的 请老师看看有什么问题? dim tb as table = e.form.controls("Table1").table dim flt as string = "" if tb.rows.count > 0 then dim ids as string for each r as row in tb.rows ids = ids & r("编号") & "," next flt = "[_Identify] not in (" & ids.trim(",") & ")" endif dim sCols() as string = {"_Identify","字段1","字段2","字段3"} dim dCols() as string = {"编号","字段1","字段2","字段3"} dim cmd as new sqlcommand cmd.c cmd.commandtext = "sel ect * from 表A where " & flt dim dt as datatable = cmd.executereader() for each dr as datarow in dt.datarows dim nr as datarow = tb.datatable.addnew() for i as integer = 0 to sCols.length-1 nr(dCols(i)) = dr(sCols(i)) next next |
-- 作者:lzzhx -- 发布时间:2017/7/18 15:09:00 -- 表B已有12000条记录了,ids 最长能达到多少?是不是长度超出了? 还有没有其它办法?
|
-- 作者:有点甜 -- 发布时间:2017/7/18 15:31:00 -- 直接查就可以查到了,没必要用idx,sql语句
select a.* from {表A} as a left join {表B} as b on a.[_Identify] = b.第一列 where b.第一列 is null |
-- 作者:lzzhx -- 发布时间:2017/7/18 15:40:00 -- where b.第一列 is null 条件不太明白,能给解释一下吗 |
-- 作者:lzzhx -- 发布时间:2017/7/18 16:19:00 -- select a.* from {表A} as a left join {表B} as b on a.[_Identify] = b.第一列 where b.第一列 is null 再加两个条件: 表A的条件 : 部门编号 in(\'1\',\'2\',\'3\') 表B的条件 : 春检年度 = 2017 (春检年度是整数形) 加上面2个条件后select语句怎么写,我怎么也试不出来
|
-- 作者:有点甜 -- 发布时间:2017/7/18 16:26:00 -- select a.* from {表A} as a left join {表B} as b on a.[_Identify] = b.第一列 where b.第一列 is null and a.部门编号 in (\'1\',\'2\',\'3\') and a.春检年度 = 2017 |
-- 作者:lzzhx -- 发布时间:2017/7/18 16:43:00 -- select a.* from {表A} as a left join {表B} as b on a.[_Identify] = b.第一列 where b.第一列 is null 查出记录 3600条 select a.* from {表A} as a left join {表B} as b on a.[_Identify] = b.第一列 where b.第一列 is null and a.部门编号 in (\'1\',\'2\',\'3\') and b.春检年度 = 2017 查出记录0条 ,应该还是 3600条才对 [此贴子已经被作者于2017/7/18 16:43:17编辑过]
|
-- 作者:lzzhx -- 发布时间:2017/7/18 17:25:00 -- 改成这样就好了 select a.* from {表A} as a left join {表B} as b on a.[_Identify] = b.第一列 and b.春检年度 = 2017 where b.第一列 is null and a.部门编号 in (\'1\',\'2\',\'3\')
|