首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

sql 哪位高手遇到这么奇怪的有关问题 字符串截取

2013-07-08 
sql 谁遇到这么奇怪的问题 字符串截取declare @location intdeclare @temp nvarchar(100) declare @temp1

sql 谁遇到这么奇怪的问题 字符串截取
declare @location int
declare @temp nvarchar(100) 
declare @temp1 nvarchar(100)
set @temp= N'周一001FL美通FL智星U31FL美服F30FL1.33FL4.75FL9.50'
 

 set @location=charindex('FL',@temp)

while @location>0
 begin
 set @temp1= SUBSTRING(@temp,0,@location)

 set @location=charindex('FL',@temp)
print @temp1
 set @temp=substring(@temp,@location+2,len(@temp)) 
end 


 结果:
周一001
美通FL智
智星
美服F30
1.33F
4.75
9.50


怎么根据"FL"  提取出来

[解决办法]
顺序有问题,如下试试

declare @location int
declare @temp nvarchar(100) 
declare @temp1 nvarchar(100)
set @temp= N'周一001FL美通FL智星U31FL美服F30FL1.33FL4.75FL9.50'
 

 set @location=charindex('FL',@temp)

while @location>0
 begin
 set @temp1= SUBSTRING(@temp,0,@location)
 print @temp1

 set @temp=substring(@temp,@location+2,len(@temp)) 
 set @location=charindex('FL',@temp)
 if(charindex('FL',@temp)=0)
 print @temp

end 

热点排行