Author |
Topic |
ladiaocb
Yak Posting Veteran
57 Posts |
Posted - 2006-12-18 : 14:50:59
|
I have a table that looks like the following:T1:id---Value1----10 10 14 202----24 24 30 583----20 26 26 30I want to parse the column "Value" to give me the unique numbers to prevent duplicate numbers showing. (I.e. Return the following:id---Value1----10 14 202----24 30 583----20 26 30)Any help as always is greatly appreciated. Happy Holidays!! |
|
cognos79
Posting Yak Master
241 Posts |
Posted - 2006-12-18 : 15:11:12
|
are the values separated each by tab or one space??? |
 |
|
ladiaocb
Yak Posting Veteran
57 Posts |
Posted - 2006-12-18 : 15:18:40
|
The values are separated each by 1 space. |
 |
|
X002548
Not Just a Number
15586 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
ladiaocb
Yak Posting Veteran
57 Posts |
Posted - 2006-12-18 : 15:35:23
|
Unfortunately this data came from raw data from a flat file. Those numbers are sequence identifiers and some of the sequences happen more than once. When I run SELECT MAX(LEN([value)) FROM T1 it returns the value "11". Thanks again for your help. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-18 : 16:01:28
|
Are there only 2-digit numbers?Peter LarssonHelsingborg, Sweden |
 |
|
ladiaocb
Yak Posting Veteran
57 Posts |
Posted - 2006-12-18 : 16:03:38
|
Yes there are only 2-digit numbers in the values column. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-18 : 16:16:59
|
[code]-- prepare test datadeclare @t table (id tinyint, value varchar(20))insert @t (id, value)select 1, '10 10 14 20' union allselect 2, '24 24 30 58' union allselect 3, '19 24 24' union allselect 4, '26 26'-- stage the datadeclare @s table (id tinyint, part varchar(20), p tinyint)insert @s (id, part)select id, substring(value, 1, 2) from @t a unionselect id, substring(value, 4, 2) from @t a unionselect id, substring(value, 7, 2) from @t a unionselect id, substring(value, 10, 2) from @t aupdate sset s.p = (select count(*) from @s q where q.id = s.id and q.part <= s.part)from @s s-- do the workselect id, ltrim(rtrim(max(case when p = 1 then part else '' end) + ' ' + max(case when p = 2 then part else '' end) + ' ' + max(case when p = 3 then part else '' end))) newcolumnvaluefrom @sgroup by id[/code]Peter LarssonHelsingborg, Sweden |
 |
|
ladiaocb
Yak Posting Veteran
57 Posts |
Posted - 2006-12-18 : 16:55:23
|
This works great!! Thanks so much for your help. |
 |
|
|