Input: This is 135 US dollars.
Output: 135
Logic: It is very simple, first of all we find the index of the first numeric character using “patindex” function. Then we find the position of white space and extract sub string that starts from numeric character and ends with white space. But there are few cases like what if number is in the last in the text then we extract sub string till the end of the text.
declare @sample table
(
data varchar(200)
)insert @sample
select ‘The amount was $874523.63’ union all
select ‘$6663.025 is already paid’ union all
select ‘You got 500 US Dollors thanks a lot’ UNION ALL
select ‘No numeric character in this line’ union all
select ‘$5567.981’ union all
select ‘you have total 250 US Dollors’select
data,
substring
(
data,
patindex(‘%[0-9]%’,data),
CASE WHEN (CHARINDEX(‘ ‘,data,patindex(‘%[0-9]%’,data)) =0 and patindex(‘%[0-9]%’,data) > 0) then LEN(data)
WHEN patindex(‘%[0-9]%’,data) = 0 THEN 0
ELSE (CHARINDEX(‘ ‘,data,patindex(‘%[0-9]%’,data)) – patindex(‘%[0-9]%’,data)) end
) as amount
from
@sample
It’s truly a nice and useful piece of info. I am happy that you simply shared this helpful info with us. Please keep us up to date like this. Thank you for sharing.
LikeLike
Have you ever considered about including a little bit more than just your articles?
I mean, what you say is important and all. Nevertheless think about if you added some
great graphics or video clips to give your posts more, “pop”!
Your content is excellent but with images and video clips, this site could definitely be one of
the very best in its niche. Terrific blog!
LikeLike
Hello Dear, are you in fact visiting this web page on a regular basis, if so
afterward you will without doubt obtain pleasant knowledge.
LikeLike
Hey There. I discovered your blog the usage of msn. This is an
extremely smartly written article. I will make sure to bookmark it and return to
read extra of your helpful information. Thanks for the post.
I’ll certainly return.
LikeLike
It’s an amazing piece of writing in favor of all the online visitors; they will obtain benefit from it I am sure.
LikeLike
Hi there every one, here every person is sharing these knowledge, thus it’s pleasant to read this web site, and I used to pay a quick visit this blog every day.
LikeLike
Outstanding post however , I was wanting to know if you could write a
litte more on this topic? I’d be very grateful if you could elaborate a little bit further. Many thanks!
LikeLike
Hello there, I found your site by way of Google whilst searching
for a similar matter, your web site got here up, it seems great.
I have bookmarked it in my google bookmarks.
Hello there, just changed into aware of your blog via Google, and located
that it is truly informative. I am gonna watch out for brussels.
I will be grateful should you continue this in future.
Numerous other folks might be benefited from your writing.
Cheers!
LikeLike
Hello there, You have done an excellent job. I will definitely digg it
and personally suggest to my friends. I’m sure they will be benefited from this website.
LikeLike
Thanks for your personal marvelous posting! I definitely
enjoyed reading it, you will be a great author. I will be sure to bookmark your blog and will eventually come back at some point.
I want to encourage you to ultimately continue your great work,
have a nice day!
LikeLike
Fastidious answers in return of this question with firm arguments and
telling the whole thing about that.
LikeLike