日期:2014-05-18  浏览次数:20351 次

怎么写一个循环

select   substring(main_style,charindex( 'http ',main_style),100)   from   dv_style
结果是137

select   substring(main_style,charindex( 'http ',main_style,138),100)   from   dv_style


我想自动的得出所有的包含‘http’这个字符串位置的详细信息,但是不想一个一个语句写,能   不能一直自动搜索,而不要我自己来写这个138

------解决方案--------------------
按http截取吧
select top 8000 iden(int,1,1)into #t from syscolumns a,syscolumns b
select substring(a.main_style,b.iden,charindex( 'http ',a.main_style+ 'http '),b.iden) from dv_style a,#t b
where b.iden <len(a.main_style) and charindex( 'http ', 'http '+a.main_style,b.iden)=b.iden
------解决方案--------------------
我不了解您表的具体结构,我就是凭自己的思路~
declare @n bigint
while @n <len(main_style) --这个地方部队,可以改,大概就是这个模式了
begin
select substring(main_style,charindex( 'http ',main_style,@n),100) from dv_style
select @n=@n+1
end