有这样一个表:
tb(File varchar(400))
File
E:\3.25\FM\河北小灵通\1.txt
E:\3.25\FM\河北小灵通\2.txt
E:\3.25\FM\河北小灵通\群发语1.txt
E:\3.25\FM\河北小灵通\群发语2.txt
E:\3.25\FM\辽宁小灵通\1.txt
E:\3.25\FM\辽宁小灵通\群发语1.txt
E:\3.25\FM\山东小灵通\1.txt
E:\3.25\FM\山东小灵通\2.txt
E:\3.25\FM\山东小灵通\群发语1.txt
E:\3.25\FM\山东小灵通\群发语2.txt我想用一查询语句得到这样的结果:Area         File                               Mo           Qfy
河北小灵通 E:\3.25\FM\河北小灵通\1.txt 1.txt 群发语1.txt
河北小灵通 E:\3.25\FM\河北小灵通\2.txt 2.txt 群发语2.txt
辽宁小灵通 E:\3.25\FM\辽宁小灵通\1.txt 1.txt 群发语1.txt
山东小灵通 E:\3.25\FM\山东小灵通\1.txt 1.txt 群发语1.txt
山东小灵通 E:\3.25\FM\山东小灵通\2.txt 2.txt 群发语2.txt

解决方案 »

  1.   

    create table tb([File] varchar(400))
    insert into tb values('E:\3.25\FM\河北小灵通\1.txt')
    insert into tb values('E:\3.25\FM\河北小灵通\2.txt')
    insert into tb values('E:\3.25\FM\河北小灵通\群发语1.txt')
    insert into tb values('E:\3.25\FM\河北小灵通\群发语2.txt')
    insert into tb values('E:\3.25\FM\辽宁小灵通\1.txt')
    insert into tb values('E:\3.25\FM\辽宁小灵通\群发语1.txt')
    insert into tb values('E:\3.25\FM\山东小灵通\1.txt')
    insert into tb values('E:\3.25\FM\山东小灵通\2.txt')
    insert into tb values('E:\3.25\FM\山东小灵通\群发语1.txt')
    insert into tb values('E:\3.25\FM\山东小灵通\群发语2.txt')
    create view v1
    as 
    select substring([file],charindex('FM\',[file])+3,5) as area,
                substring([file],charindex('群发语',[file]) ,len([file])-charindex('群发语',[file])+1) as qfy,
                substring([file],charindex('发语',[file])+2,charindex('.txt',[file])-2-charindex('发语',[file])) as no
    from  tb
    where charindex('群发语',[file])<>0go
    create view v2
    as
    select  [file], substring([file],charindex('FM\',[file])+3,5) as area,
                substring([file],charindex('通\',[file])+2 ,len([file])-charindex('通\',[file])-1) as mo,
                substring([file],charindex('通\',[file])+2,charindex('.txt',[file])-2-charindex('通\',[file])) as no
    from  tb
    where charindex('群发语',[file])=0
      

  2.   

    结果
    河北小灵通 E:\3.25\FM\河北小灵通\1.txt 1.txt 群发语1.txt
    河北小灵通 E:\3.25\FM\河北小灵通\2.txt 2.txt 群发语2.txt
    辽宁小灵通 E:\3.25\FM\辽宁小灵通\1.txt 1.txt 群发语1.txt
    山东小灵通 E:\3.25\FM\山东小灵通\1.txt 1.txt 群发语1.txt
    山东小灵通 E:\3.25\FM\山东小灵通\2.txt 2.txt 群发语2.txt