1

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?

  1. Value in 2nd brackets
  2. Value after 2nd set of brackets
1
  • 5
    Which DBMS are you using? Commented Oct 26, 2016 at 15:58

2 Answers 2

1

SQL Server

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
;

MySQL

select  substring_index(substring_index(testvalue ,'[',-1),']',1)
       ,substring_index(testvalue ,']',-1)

from    testtable
;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you but do you know how to accomplish this in SQL Server?
0

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

1 Comment

Thank you but do you know how to accomplish this in SQL Server?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.