Rip data from string

Can anyone help me to rip data from a string?  I have not been able to get it correct as it is not always the same one example  "4 X "5.02 X "5.32    another may be 2.5" X .75"  X 3" .
stevendeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
What output you need from your input.
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Are those mathematics expressions?
0
stevendeveloperAuthor Commented:
Sorry not mathematics, just a measurement. I need the numbers only
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Pawan KumarDatabase ExpertCommented:
"4 X "5.02 X "5.32  -------> 45.025.32 ??
0
stevendeveloperAuthor Commented:
No just              4  
                          5.02
                          5.32
0
Pawan KumarDatabase ExpertCommented:
3 rows ?
0
stevendeveloperAuthor Commented:
One row would fine with each value
0
Pawan KumarDatabase ExpertCommented:
Do you have a table where these values are stored?
0
stevendeveloperAuthor Commented:
Yes columns od, id, length
0
Pawan KumarDatabase ExpertCommented:
Please try full tested solution for you

Create table and data generation-

CREATE TABLE Rip
(
	a VARCHAR(100)
)
GO

INSERT INTO Rip VALUES
('"4 X "5.02 X "5.32'),('2.5" X .75"  X 3"')

Open in new window


Solution

SELECT 
	  LTRIM(RTRIM(REPLACE(SUBSTRING(a,0,CHARINDEX('X',a,0)),'"',''))) od
	 ,LTRIM(RTRIM(REPLACE(SUBSTRING(a,CHARINDEX('X',a,0)+1,CHARINDEX('X',a,CHARINDEX('X',a,0)+1) - CHARINDEX('X',a,0) -1),'"',''))) id
	 ,LTRIM(RTRIM(REPLACE(SUBSTRING(a,CHARINDEX('X',a,CHARINDEX('X',a,0)+1)+1,LEN(a)),'"',''))) length
FROM Rip

Open in new window


OUTPUT

/*------------------------
OUTPUT
------------------------*/

(2 row(s) affected)
od        id           length
--------- ------------ ------------
4         5.02         5.32
2.5       .75          3

(2 row(s) affected)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stevendeveloperAuthor Commented:
Id gives me the below error,

Msg 537, Level 16, State 3, Line 2
Invalid length parameter passed to the LEFT or SUBSTRING function.


the OD and Length are correct!!  Excellent  We are running sql 2012 r2
0
Pawan KumarDatabase ExpertCommented:
How many rows are there in your table? can you send you data to me in an excel?
0
stevendeveloperAuthor Commented:
There are many but I only pulled the top 100 and got the error.
test.xlsx
0
stevendeveloperAuthor Commented:
Blew out on  2" DIA. X 6"  the 60th row...
0
Pawan KumarDatabase ExpertCommented:
What should be the output for above.
0
stevendeveloperAuthor Commented:
I got it used a case to find DIA and use null
0
stevendeveloperAuthor Commented:
Thank you Pawan.  I was able to use this just fine!  excellent job
0
Pawan KumarDatabase ExpertCommented:
Welcome. Happy to help as always. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.