I have data in sql
(Just to note: SQL STudio
is the IDE
) like:
data
a_10_b_c
a_1_b_c
I want to get the data between first two symbols _
:
Output
10
1
I have data in sql
(Just to note: SQL STudio
is the IDE
) like:
data
a_10_b_c
a_1_b_c
I want to get the data between first two symbols _
:
Output
10
1
This would be my approach:
First you transform this to an XML and then you pick the second node..
EDIT: Some more examples where this approach is usefull:
CROSS APPLY: You can use this approach to get several tokens at once
CTE: use as parameter
Split String: Transform to list
Dynamic IN Statement
You can do this with nested string functions. Often, this is simpler using
outer apply
: