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 |
zeeshan13
Constraint Violating Yak Guru
347 Posts |
Posted - 2007-08-02 : 11:11:02
|
Hi All,I have a table called Table1. It has a field called con_upc_no with varchar type. All records in con_upc_no field has a length of 13 characters, and have the following type of records.00079400827900007940082344In my select I want to get it like following.000-7940-082790000-7940-082344What is the simplest way to get it in above format?.Looking for a quick response.Thanks,Zee |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-08-02 : 11:19:16
|
[code]DECLARE @Sample TABLE (Col1 VARCHAR(20))INSERT @SampleSELECT '0007940082790' UNION ALLSELECT '0007940082344'SELECT Col1, STUFF(STUFF(Col1, 8, 0, '-'), 4, 0, '-'), LEFT(Col1, 3) + '-' + SUBSTRING(Col1, 4, 4) + '-' + RIGHT(Col1, 6)FROM @Sample[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
zeeshan13
Constraint Violating Yak Guru
347 Posts |
Posted - 2007-08-02 : 11:30:38
|
Thanks :).I dont understand how STUFF works.Can you please explain.Thanks for all your help :) .... |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-08-02 : 11:54:27
|
I think it is better you spend YOUR time reading about it Books Online. E 12°55'05.25"N 56°04'39.16" |
 |
|
zeeshan13
Constraint Violating Yak Guru
347 Posts |
Posted - 2007-08-02 : 11:55:57
|
I will. Thanks again... |
 |
|
|
|
|
|
|