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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Pull the appropriate number from string

Author  Topic 

dahinda61428
Starting Member

2 Posts

Posted - 2014-11-26 : 12:35:47
Hello,

I have a field that is populated with a week number, a year and other characters. For example: OSF-2014-wk-15. I need to pull out the week number at the end of the string. The week number can be a two number week as above or a one number week such as OSF-2014-wk-6. I used the Right function, RIGHT(A.Week, 2), but that pulls in the dash if it is a one number week. How can I determine if it is a one number week or two and pull the appropriate number? I do not want the dash.

Thank you for all your help!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-26 : 12:40:48
select replace(right(yourcolumn, 2), '-', '')
from yourtable

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

dahinda61428
Starting Member

2 Posts

Posted - 2014-11-26 : 13:22:08
Thank you!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-26 : 13:30:41


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -