Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Finding Substring With Delimiter SQL

Lets say I have a dimension, called "Custom1" that can be 47x29x10 , 01x8x300…etc.

How can I split on the "x" delimiter regardless of the length between the delimiters?

I was successfully able to capture the first and last numbers, but the middle number is giving me trouble.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is the code I have already


SELECT

TRIM(SUBSTRING(Custom1, 1, CHARINDEX(‘x’,Custom1)-1)) as Length,

SUBSTRING(Custom1, CHARINDEX(‘x’, Custom1) +1, LEN(Custom1) – CHARINDEX(‘x’, Custom1)) as Widths,

REVERSE(SUBSTRING(REVERSE(Custom1),0,CHARINDEX(‘x’,REVERSE(Custom1)))) as Height

FROM Table

>Solution :

you can check this code and tell me if it helps you

SELECT
    PARSENAME(REPLACE(Custom1, 'x', '.'), 3) as Length,
    PARSENAME(REPLACE(Custom1, 'x', '.'), 2) as Width,
    PARSENAME(REPLACE(Custom1, 'x', '.'), 1) as Height
FROM YourTable;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading