SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 insert character into a string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

HenryFulmer
Yak Posting Veteran

USA
98 Posts

Posted - 07/16/2012 :  16:43:10  Show Profile  Reply with Quote
I need to manipulate a string value by inserting a '-' character into the string. I have two different string formats: one is made from numbers only and always eight digits long. I need to insert the character after the first 4 digits. The other one starts allways with 2 letters and can be between 4 and 16 characters long and I need to insert the - after the first 2 characters.
Any help would be appreciated.
Thanks.

robvolk
Most Valuable Yak

USA
15557 Posts

Posted - 07/16/2012 :  17:39:17  Show Profile  Visit robvolk's Homepage  Reply with Quote
SELECT STUFF(col, CASE WHEN col LIKE '[a-z][a-z]%' THEN 3 ELSE 5 END, 0, '-')
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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