读书人

sql 哪位高手遇到这么奇怪的有关问题

发布时间: 2013-07-09 09:50:48 作者: rapoo

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 @location=charindex('FL',@temp) 这个应该在和下面那个换下位置

set @temp1= SUBSTRING(@temp,0,@location)

print @temp1
set @temp=substring(@temp,@location+2,len(@temp)-LEN(@temp1))
end

[解决办法]

引用:
你写的有两处问题
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 @location=charindex('FL',@temp) 这个应该在和下面那个换下位置

set @temp1= SUBSTRING(@temp,0,@location)

print @temp1
set @temp=substring(@temp,@location+2,len(@temp)-LEN(@temp1))
end




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)- LEN(@temp1))
set @location=charindex('FL',@temp)
end


根据 小爱 修改的来
sql  哪位高手遇到这么奇怪的有关问题
sql  哪位高手遇到这么奇怪的有关问题
[解决办法]
declare @location int
declare @temp nvarchar(100)
declare @tempa nvarchar(100)
set @temp=N'周一001FL美通FL智星U31FL美服F30FL1.33FL4.75FL9.50'''
set @location=charindex('FL',@temp)
while @location>0
begin
set @tempa=substring(@temp,0,@location)
--print @tempa

set @temp=substring(@temp,@location+2,len(@temp))
print @tempa
set @location=charindex('FL',@temp)
end
if @location =0 and len(@temp)>0
begin
print @temp

end



周一001
美通
智星U31
美服F30
1.33
4.75
9.50'
[解决办法]

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

set @temp=@temp+'FL' --在结尾再加上一个分隔符
set @location=charindex('FL',@temp)
while @location>0
begin
set @location=charindex('FL',@temp)--这个要放前面
set @temp1= SUBSTRING(@temp,0,@location)

print @temp1

set @temp=substring(@temp,@location+2,len(@temp))
end

result:
周一001
美通
智星U31
美服F30
1.33
4.75
9.50
[解决办法]

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)
end
print @temp


print SUBSTRING(@temp,0,len(@temp))

读书人网 >SQL Server

热点推荐