2011-11-10 2 views

답변

3

날짜를 얻으려면 PATINDEX()을 사용할 수 있습니다.

declare @yourString varchar(100) 
set @yourString = 'on 01-15-09 with a factor of 0.8' 

select substring(@yourString, 
      patindex('%[0-9][0-9]-[0-9][0-9]-[0-9][0-9]%', @yourString), 
      8) 

는 "XX의 요인"을 얻기 위해 당신이 할 수

select substring(@yourString, 
     patindex('%with a%', @yourString) + 7, 
     20) 
+1

@VikrantMore하지 내가 알고있다. 벗어나기 위해서는 특정한 패턴이 필요합니다. 날짜는 쉽지만, 앞의 문자열을 모르는 경우 "xx 인수"를 찾는 것은 불가능합니다. 내가 무슨 말하는지 보렴? –

1
declare @txt varchar(max) 
set @txt = 'on 01-15-09 witha factor of 0.8' 

select cast(substring(@txt, patindex('% [0-9][1-9]-%', @txt), 9) as date) [date], 
cast(right(@txt, patindex('%_ %', reverse(@txt))) as decimal(9,1)) Factor 

결과 :

date  Factor 
---------- ------ 
2009-01-15 0.8 
관련 문제