lukepapa
asked on
SQL Substring and Patter return
Hi experts,
In my SQL 2005 database I have a string that looks like the following:
gerling allg konzern - umbrella excess of loss (1.03: motor)
What I want to do is return only the '1.03' from within the string.
Not only this, it maybe the case where it could be 1.01.01 and also 1.01.01.xx.xx.xx
Could somone help me with this please, I am stuck!
In my SQL 2005 database I have a string that looks like the following:
gerling allg konzern - umbrella excess of loss (1.03: motor)
What I want to do is return only the '1.03' from within the string.
Not only this, it maybe the case where it could be 1.01.01 and also 1.01.01.xx.xx.xx
Could somone help me with this please, I am stuck!
select SUBSTRING (String, CHARINDEX('(' ,String )+1, CHARINDEX(':', String) - CHARINDEX('(' ,String )-1 ) from urTable
ASKER
Hi thanks for the quick response, when I run this I get the following error:
Msg 536, Level 16, State 3, Line 1
Invalid length parameter passed to the substring function.
(1009 row(s) affected)
Msg 536, Level 16, State 3, Line 1
Invalid length parameter passed to the substring function.
(1009 row(s) affected)
select SUBSTRING (String, CHARINDEX('(' ,String )+1, CHARINDEX(':', String) - CHARINDEX('(' ,String )-1 ) from urTable
WHERE String like '%(%:%)'
WHERE String like '%(%:%)'
ASKER
Hi, still no joy. I get the same error as previously.
can u please return the output of this query
SELECT *
from urTable
WHERE String like '% (%:%)'
SELECT *
from urTable
WHERE String like '% (%:%)'
ASKER
Please find document attached with output of query
layer.xlsx
layer.xlsx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much, I appreciate your time helpling me :-)
ASKER
How about if I wanted to select a string which contains (xxxxxxxxxx) and I needed to remove everything in the brackets - xxxxxxxxx and the brackets themselves................ .