Please start any new threads on our new site at http://forums.sqlteam.com. 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
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Adding Zeros to String
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Brittney10
Posting Yak Master

USA
154 Posts

Posted - 04/01/2013 :  18:24:13  Show Profile  Reply with Quote
I need to add zeros to the front of two words, or numbers, that are before or after an asterisk depending on the length of each string . The digits before the asterisk should have a total length of 5 and the digits after the asterisk should have a total count of 6. To makeup the appropriate 5 or 6 length when digits/numbers are missing, a zero should be appended to the front of the string. The asterisk should also be completely stripped from the string in the final output.

For example:

1234*12345 would become 01234012345.

123*1234 would become 00123001234.

Thanks for the help in advance.

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 04/01/2013 :  21:56:51  Show Profile  Reply with Quote
	RIGHT('00000'+LEFT(YourColumn,CHARINDEX('*',YourColumn)-1),5) +
	+RIGHT('00000'+STUFF(YourColumn,1,CHARINDEX('*',YourColumn),''),5)
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.05 seconds. Powered By: Snitz Forums 2000