| Author |
Topic |
|
mike13
Posting Yak Master
219 Posts |
Posted - 2007-07-28 : 18:27:48
|
| Hi all,i´m wondering how to do this.i got a field, and in that field i have list of words ex:houseboatcarroaddogsunboatroadi know how to do this in ASP.net code but seems a waste of resources selecting to all , to the asp and then back to sql.must be a better way of doing this.tnx,Mike |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2007-07-28 : 18:46:39
|
| Is it single column table? If not, how do you know which row should be deleted? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-28 : 18:50:19
|
delete ffrom (select row_number() over (partition by wordcol) as recid from wordtable) as fwhere recid > 1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
mike13
Posting Yak Master
219 Posts |
Posted - 2007-07-29 : 05:07:58
|
| HI,No row should be deleted at all, the duplicated are the content of one field, i want to remove the duplicates from that field ex:Select word from T_words where id=10and content of the field word has the duplicateshouseboatcarroaddogsunboatroadseparated by <ENTER>so i want to remove the duplicates, probably need to delete the content to update with the right onetnx |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-29 : 12:52:22
|
You know this is REALLY bad design? I feel sorry for you to maintain this application.Make use of a CSV-SPLIT function (may replace comma with CRLF). There are many here at SQL Team. Also use the CROSS APPLY keyword.Then select the distinct combination and put back as concatenated string. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-29 : 13:04:14
|
Or just plainSELECT DISTINCT t1.PrimaryCol, STUFF((SELECT DISTINCT TOP 100 PERCENT ',' + f.Part FROM WordTable AS t2 CROSS APPLY Csv_Split(t2.PrimaryCol) AS f WHERE t2.PrimaryCol = t1.PrimaryCol ORDER BY ',' + f.Part FOR XML PATH('')), 1, 1, '') AS CODESFROM WordTable AS t1ORDER BY t1.PrimaryCol E 12°55'05.25"N 56°04'39.16" |
 |
|
|
mike13
Posting Yak Master
219 Posts |
Posted - 2007-07-29 : 17:01:11
|
| Hi Peso,you say it is bad design having having CRLF in my DB field?so beter replace them with commas insted of CRLF.TO be honest now the only reason i use CRLF is because the word lists are CRLF separated i split them in my code and put them in array and use them but should matter splitting on the comma or crlf. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|