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 |
|
Gratin
Starting Member
6 Posts |
Posted - 2008-01-31 : 10:41:21
|
| Good afternoon,I hope the title is self explaining. Here is an example of what i would like to do:Before...11.11.1.11.2.11.3.11.10.1After...0101.0101.01.0101.02.0101.03.0101.10.01Thanks,Phil. |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2008-01-31 : 10:54:01
|
| Could you elaborate , are the numbers currently in a table or are you passing these through a stored procedure?Jack Vamvas--------------------Search IT jobs from multiple sources- http://www.ITjobfeed.com |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-01-31 : 10:58:05
|
| [code]select a.num, Legal_Num = isnull(right('00'+parsename(a.num,3),2)+'.','')+ isnull(right('00'+parsename(a.num,2),2)+'.','')+ isnull(right('00'+parsename(a.num,1),2),'')from ( -- Test Data select num = '1' union all select num = '1.1' union all select num = '1.1.1' union all select num = '3.2.1' union all select num = '1.3.1' union all select num = '1.10.1' ) aResults:num Legal_Num ------ --------- 1 011.1 01.011.1.1 01.01.013.2.1 03.02.011.3.1 01.03.011.10.1 01.10.01(6 row(s) affected)[/code]CODO ERGO SUM |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Gratin
Starting Member
6 Posts |
Posted - 2008-01-31 : 11:14:34
|
| Thanks very much Michael ;) It works perfectly.See you,Phil. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-31 : 11:17:43
|
Slighty simpler (just in case there are more parts than four).select a.num, substring(replace('.' + a.num, '.', '.0'), 2, 8000) as Legal_Numfrom ( select num = '1' union all select num = '1.1' union all select num = '1.1.1' union all select num = '3.2.1' union all select num = '1.3.1' union all select num = '1.10.1' ) a E 12°55'05.25"N 56°04'39.16" |
 |
|
|
Gratin
Starting Member
6 Posts |
Posted - 2008-02-01 : 06:26:59
|
| Sorry Peso, we want only 2 digits between the dots. It doesn't give exactly the result required :3.9.2 03.09.023.10 03.0103.11 03.0113.12 03.0123.13 03.0133.13.1 03.013.01I'll stick with Michael solution and add 2 levels.Thanks again to all of you.Phil. |
 |
|
|
|
|
|
|
|