How to extract data after 2nd last space up to 10 characters from a SQL Server column?
Column data is below:
INV PNI S000060803 1
INV PNI P000035365 132
INV PRVC S000059468 4
INV PIV P000034785 2
INV PIV T000034785 27
Desired result is:
S000060803
P000035365
S000059468
P000034785
T000034785
3条答案
按热度按时间kulphzqa1#
You can use syntax working with all versions of SQL Server like this. It's a little bit messy, but should work on any version starting with 2005 at least. I'm using CTE just for demo to create virtual table.
qvtsj1bj2#
Please try the following solution based on the
PARSENAME()
function use.A minimal reproducible example is not provided. 😒
An assumption is made that the tokens column has just a single space character between words/tokens.
SQL #1
SQL #2
Implementation when there are multiple spaces between words/tokens.
Output
ddrv8njm3#
Late answer, but here is another option