Link to home
Start Free TrialLog in
Avatar of lukepapa
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!
Avatar of Aneesh
Aneesh
Flag of Canada image

select SUBSTRING (String, CHARINDEX('(' ,String )+1, CHARINDEX(':', String) - CHARINDEX('(' ,String )-1 )  from urTable
Avatar of lukepapa
lukepapa

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)
select SUBSTRING (String, CHARINDEX('(' ,String )+1, CHARINDEX(':', String) - CHARINDEX('(' ,String )-1 )  from urTable
WHERE String like '%(%:%)'
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 '% (%:%)'
Please find document attached with output of query
layer.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks very much, I appreciate your time helpling me :-)
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.................