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 2008 Forums
 Transact-SQL (2008)
 insert character into a string

Author  Topic 

HenryFulmer
Posting Yak Master

110 Posts

Posted - 2012-07-16 : 16:43:10
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

15732 Posts

Posted - 2012-07-16 : 17:39:17
SELECT STUFF(col, CASE WHEN col LIKE '[a-z][a-z]%' THEN 3 ELSE 5 END, 0, '-')
Go to Top of Page
   

- Advertisement -