create table #text_table (text_field varchar(250))
insert into #text_table values
('Scheme ELS updated. Reserve Authority Level changed from: 11000000.00 to: 8000000.00.'),
('Scheme CNST updated. Payment Authority Level changed from: 8000000.00 to: 10000000.00. Reserve Authority Level changed from: 8000000.00 to: 10000000.00.'),
('Scheme ELS updated. Payment Authority Level changed from: 350000.00 to: 100000.00.')
drop table #text_table2
select *,
case when charindex('Reserve', text_field ,0) > 0 and charindex('Payment', text_field,0) = 0 then 'Reserve'
when charindex('Payment', text_field,0) > 0 and charindex('Reserve', text_field,0) = 0 then 'Payment'
when charindex('Payment', text_field,0) > 0 and charindex('Reserve', text_field,0) > 0 then 'Both'
else 'N/A' end as tag,
charindex('from: ',text_field,0) as From_Index,
charindex(' to: ',text_field, charindex('from: ',text_field,0)) as to_index,
charindex('.',text_field, charindex(' to: ',text_field, charindex('from: ',text_field,0))) as dot_index
into #text_table2
from #text_table
select *
into #simple
from #text_table2 where tag in ('Reserve','Payment')
select
substring(text_field, 0, charindex('.00. ',text_field,0)+3) as text_field
into #parse
from #text_table2 where tag = 'Both'
union
select
substring(text_field, charindex('.00. ',text_field,0)+5, charindex('.00.',text_field,charindex('.00.',text_field,0)+3))
from #text_table2 where tag = 'Both'
insert into #simple
select *,
case when charindex('Reserve', text_field ,0) > 0 and charindex('Payment', text_field,0) = 0 then 'Reserve'
when charindex('Payment', text_field,0) > 0 and charindex('Reserve', text_field,0) = 0 then 'Payment'
when charindex('Payment', text_field,0) > 0 and charindex('Reserve', text_field,0) > 0 then 'Both'
else 'N/A' end as tag,
charindex('from: ',text_field,0) as From_Index,
charindex(' to: ',text_field, charindex('from: ',text_field,0)) as to_index,
charindex('.',text_field, charindex(' to: ',text_field, charindex('from: ',text_field,0))) as dot_index
from #parse
select *,
substring(text_field, from_index+6, to_index - from_index - 6) as From_Value,
substring(text_field, to_index+4, dot_index - to_index - 1) as To_Value
from #simple
能否請您發佈預期輸出 – TheGameiswar
基於'charindex'值很多'substring'操縱一些'那裏像「%%」'的查詢結果欄是什麼,你應該尋找。 – beercodebeer
你好。預期產出是四個coulumns:ReserveFrom,ReserveTo,PaymentFrom和PaymentTo。我需要這些列中的結果來自紅色的「文本列」cvalues。 – AJCT