Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Is there any function to separate numeric values

Author  Topic 

karthik0805
Starting Member

14 Posts

Posted - 2012-09-28 : 06:39:29
Is there any function to separate numeric values and characters in SQL?

for example :

String:'56879port782'

Can we separate the numeric values from above string?
expecting output is : '56879782'

arpana patil
Starting Member

24 Posts

Posted - 2012-09-28 : 06:55:56
CREATE Function [dbo].[RemoveNonNumericCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin

While PatIndex('%[^0-9]%', @Temp) > 0
Set @Temp = Stuff(@Temp, PatIndex('%[^0-9]%', @Temp), 1, '')

Return @TEmp
End
Go to Top of Page

karthik0805
Starting Member

14 Posts

Posted - 2012-09-28 : 07:22:10
Thank you, Arpana!
Go to Top of Page

arpana patil
Starting Member

24 Posts

Posted - 2012-09-28 : 07:29:50
welcome
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-10-05 : 05:08:22
Other techniques http://beyondrelational.com/modules/2/blogs/70/posts/10946/extract-only-numbers-from-a-string-part-3.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -