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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Is this possible?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

249 Posts

Posted - 12/13/2012 :  10:53:20  Show Profile  Reply with Quote
Hi guys,

I need to make some string to numeric. See following:

Cast(Right(CodeNum, 1) as Int)

But the dilemma is CodeNum has values as ABC3, BBC14. I know I can make the CodeNum as ABC03 and change the Right() function to Right(CodeNum, 2) but for some reason, it will take a lot of work to do that. So what is the easier way to solve this?
Appreciate your time!

Flowing Fount of Yak Knowledge

United Kingdom
3385 Posts

Posted - 12/13/2012 :  11:04:25  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
patindex('%[^0-9]%',CodeNum) will give the position of the first non numeric character
to start from the end patindex('%[^0-9]%',reverse(CodeNum))
So the number of numeric characters is patindex('%[^0-9]%',reverse(CodeNum)) - 1


Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Posting Yak Master

249 Posts

Posted - 12/13/2012 :  11:19:06  Show Profile  Reply with Quote
wow, this is something looks like c#, thank you so much.
This is great, thanks!!!
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 12/14/2012 :  01:39:05  Show Profile  Reply with Quote

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000