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.
| Author |
Topic |
|
tooba
Posting Yak Master
224 Posts |
Posted - 2011-03-16 : 20:38:45
|
| Hi guys, I have source data like this listed below:-Code123457869975689I want to add '-' after 2 character Example:-Code12-34578-69975-689Help me out how i can accomplish, Thanks. |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2011-03-16 : 21:36:10
|
| select left(code,2) + '-' + right(code,3)from yourtable |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-03-16 : 21:41:40
|
Or, use my favorite function - the one and only STUFF.update YourTable set YourColumn = stuff(YourColumn,3,0,'-') |
 |
|
|
tooba
Posting Yak Master
224 Posts |
Posted - 2011-03-16 : 22:26:03
|
| Hi sunitabeck, thanks for your reply, quick question, could you please advise me what is "stuff" in your statement?update YourTable set YourColumn = stuff(YourColumn,3,0,'-') |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-03-16 : 22:29:50
|
| stuff is a SQL function that inserts one string into another. See this MSDN page: http://msdn.microsoft.com/en-us/library/ms188043.aspx |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-03-18 : 03:47:25
|
| If it is only for display use it in a select statementselect stuff(YourColumn,3,0,'-') from tableMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|