字符串拆解问题,请帮忙看看!TKS!

KnitsEDI 2013-03-29 04:16:32
现有一串字符,如'收货1->收货2->检查->校对..............->处理完成'
中间的......为省略的工序,工序名称之间用->进行连接,
现在想把此字符串拆解成如下表格显示:
iden 工序名
1 收货1
2 收货2
3 检查
4 校对
.............
N 处理完成

请高手帮忙指点.
...全文
243 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
KnitsEDI 2013-03-29
  • 打赏
  • 举报
回复
谢谢!方法OK!在网上也搜到了其它方法。
smallapple888 2013-03-29
  • 打赏
  • 举报
回复
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

水族杰纶 2013-03-29
  • 打赏
  • 举报
回复
字符串拆分 搜吧 很多

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧