正在努力编写SUBSTRING
函数以从下面提到的字符串中提取值。
String1 = [The Aggregate Total Incremental Facility Commitments shall not, at any time, exceed [10 million].]
预期输出:String1 = 10 million
String2 = a Borrower (or the Parent) may select an Interest Period of [[ 12] or [24]] Months
预期输出:String2 = [[ 12] or [24]] Months
String3 = excluding all intra-group items and investments in Subsidiaries of any member of the Group) exceeds [10]% of [ABC]
预期输出:String 3 = [10]%
答案 0 :(得分:1)
尝试以下操作:
declare @String1 varchar(1000)= '[The Aggregate Total Incremental Facility Commitments shall not, at any time, exceed [10 million].]'
declare @String2 varchar(1000)= 'a Borrower (or the Parent) may select an Interest Period of [[ 12] or [24]] Months'
declare @String3 varchar(1000)= 'excluding all intra-group items and investments in Subsidiaries of any member of the Group) exceeds [10]% of [ABC]'
select substring(@string1, charindex('[', @string1, 2)+1, charindex(']', @string1, 1)-charindex('[', @string1, 2)-1)
select substring(@string2, charindex('[', @string2, 1), 100)
select substring(@string3, charindex('[', @string3, 1), charindex('%', @string3, 1)-charindex('[', @string3, 1)+1)
N.B。 :答案仅针对给定的字符串。