一个表 a表 有一列tt
一个表 b表 t1 t2两列
t1不为空取t1,t1为空取t2
然后筛选
如果这列开头是022,则从第四位向后取六位
如果无前缀的从第一位向后取六位
然后这六位和a表那列的数比对,相同就将b表这行数据插入一个新表
最后导出这个新表这个过程方法应该怎么写呢.. 数据量很大 3W行 请考虑运行速度的情况下弄...
之前的csv文件读取和插入数据库就搞的我很头疼了..
话说 插入方法还是挺郁闷 我考虑想弄个进度条来做 但是还没弄 悲剧啊..
太纠结了 技术不给力 求大伙帮忙 谢谢了

解决方案 »

  1.   

    存到dataset里面,然后根据条件一条条分析判断,进度条也可以做的,count总数为进度条的Max值,当前循环行为value值
      

  2.   


    SELECT a.tt, nb.nt
    FROM a INNER JOIN
    (
      SELECT (CASE SUBSTRING(ISNULL(t1, '') + t2, 1, 3)
              WHEN '022' THEN SUBSTRING(ISNULL(t1, '') + t2, 4, 6)
              ELSE SUBSTRING(ISNULL(t1, '') + t2, 1, 6) END) AS nt
      FROM b
    ) AS nb ON a.tt = nb.nt
      

  3.   


    if object_id('a表') is not null
    drop table a表
    create table a表(tt varchar(6)) --a表
    insert into a表 select '123456' union all
    select '234567' union all
    select '345678' union all
    select '456789'
    if object_id('b表') is not null
    drop table b表
    create table b表(t1 varchar(50),t2 varchar(50)) --b表
    insert into b表 select '022123456',null union all
    select   null,'022234567' union all
    select  '033345678',null union all
    select  null,'044456789'if object_id('新表') is not null
    drop table 新表
    create table 新表(tt varchar(6)) --新表delete from 新表--插入语句
    insert into 新表
    select t4.tt from a表 inner join 
    (select case when charindex('022',t)=1 then substring(t,4,6) else substring(t,1,6) end as tt
    from
    (select case when  t1 is null then t2 when t2 is null then t1 end as t from b表)t3)t4
    on a表.tt=t4.ttselect * from 新表 --查看结果--结果
    --tt
    123456
    234567
      

  4.   

    昨天不要意思 忘记来了 是access的数据库. 话说不知道有没字符串截取函数.
    貌似sql的是substr..
      

  5.   

    SELECT  SUBSTR(phone,4,10) FROM b表 WHERE SUBSTR(phone,1,3)='022'这个是我朋友给我写的一个 sql的
      

  6.   

    个人觉得access的更好做的吧,还本地的,速度就快多了
      

  7.   

    用Linq to SQL的解决方案吧
      

  8.   

    access 是 Left Mid Right
      

  9.   

    o(︶︿︶)o 唉 尼玛j8 boss 收完人家预付的钱 我给写了个半成品就给人家了 木有做细致的筛选.
    反正我也离开了 但是尼玛倒霉boss竟然这个项目没给我money.. 屮啊..
    现在结贴了 回答的都有分