I'm using SQL Server 2014 ....
Select testvalue from testtable
returns
[000001][xXCEWkC+WDhe7EYo6feDmQ==]mnjQ3UkMjb1swK1wCTT75Q==
How can I split this value into 2 different values?
- Value in 2nd brackets
- Value after 2nd set of brackets
I'm using SQL Server 2014 ....
Select testvalue from testtable
returns
[000001][xXCEWkC+WDhe7EYo6feDmQ==]mnjQ3UkMjb1swK1wCTT75Q==
How can I split this value into 2 different values?
select right(testvalue,charindex(']',reverse(testvalue))-1) as col_1_option_a
,right(testvalue,len(testvalue)-patindex('%][^[]%',testvalue)) as col_1_option_b
,right(left(testvalue,patindex('%][^[]%',testvalue)-1),patindex('%][^[]%',testvalue)-charindex(']',testvalue)-2) as col_2
from testtable
;
select substring_index(substring_index(testvalue ,'[',-1),']',1)
,substring_index(testvalue ,']',-1)
from testtable
;
If you are using MySQL, you can use substring and locate:
SELECT SUBSTR(testvalue,
1,LOCATE("]",testvalue,LOCATE("]",testvalue)+1)) AS column1,
SUBSTR(testvalue,
LOCATE("]",testvalue,LOCATE("]",testvalue)+1)+1) AS column2 FROM testtable