Example string: " s:6:"module";s:11:"leadCapture"; " --Note: s is not important.
I tried using string_split
:
SELECT value
into temp
FROM STRING_SPLIT('s:6:"module";s:11:"leadCapture";s:6:"action";s:5:"save2";', ';');
select * from temp;
Below is the output:
Row 1: s:6:"module"
Row 2: s:11:"leadCapture"
Row 3: s:6:"action"
Row 4: s:5:"save2"
Expected Output:
6 - column 1,
module - column 2,
11 - column 3,
leadcapture - column 4.
1条答案
按热度按时间dba5bblo1#
The following code will work starting with MS SQL Server 2016:
Ugly and convoluted, but at the time of writing this is your only option if you want to do it in pure SQL in an on-prem instance. The alternatives are:
string_split()
function, which accepts an additional parameter,enable_ordinal
. This will add an extra column into its output containing ordinal position of substrings within a string. If you use Azure version of SQL, or somehow have SQL Server 2022, this will allow you to avoid having to deal with JSON.