|
I have a need to pull an amount from a column (varchar 450) that contains text like the following
(comments are locked)
|
|
Is the second period the last period in your text string? If so you can reverse the column to get the position and use that in your substring. I sure hope so, let's say it is
Mar 07 '11 at 10:51 AM
farid nia
This works if you need the - in the value, if not it is easy to remove. DECLARE @COLUMN varchar(50)
Mar 07 '11 at 11:00 AM
Tim
If I had some samples of the results you get from your source table I could test this for your scenario.
Mar 07 '11 at 11:00 AM
Tim
Thanks Tim
Mar 07 '11 at 11:59 AM
farid nia
@Farid Nia after playing with the data a bit more, I think this will be the best solution for you. It takes into consideration having or not having a minus in the dollar amount. DECLARE @COLUMN varchar(50) SET @COLUMN = 'GOASDOGLE 108092.43. | Error<cpaASDF_errrror' SELECT SUBSTRING(@column,PATINDEX('%[0-9-]%',@column),(LEN(@column)-PATINDEX(('%.%'),REVERSE(@COLUMN)))-PATINDEX('%[0-9-]%',@column)+1)
Mar 07 '11 at 01:40 PM
Tim
(comments are locked)
|
|
If the pipe character is reliable then you could use
(comments are locked)
|

