日期:2014-05-17  浏览次数:20439 次

字符串拆解问题,请帮忙看看!TKS!
现有一串字符,如'收货1->收货2->检查->校对..............->处理完成'
中间的......为省略的工序,工序名称之间用->进行连接,
现在想把此字符串拆解成如下表格显示:
iden     工序名
1         收货1
2         收货2
3         检查
4         校对
.............
N         处理完成

请高手帮忙指点.

------解决方案--------------------
字符串拆分
搜吧 很多
------解决方案--------------------
declare
  @sString varchar(Max),
  @length integer
  
   create table #temp
  (
     id integer identity(1,1),
     TName varchar(20)
   )
  set @sString='收货1->收货2->检查->校对->处理完成'

  while len(@sString)>0 
  begin
    set @length=charindex('->',@sString)
    if @length>0
    begin
      insert into #temp (TName) select substring(@sString,1,@length-1)
      set @length=@length+2
      set @sString= substring(@sString,@length,len(@sString))
    end
    else
    begin
      if @length=0
      begin
        insert into #temp (TName) select @sString  
        set @sString=''
      end
    end
  end   

  select * from #temp