| Author |
Topic |
|
LacOniC
Starting Member
29 Posts |
Posted - 2008-02-14 : 08:57:11
|
| I have a table like that:ColumnA ColumnB ColumnC-------------------------------Alice Lukas Alice.LucasJames Redford James.RedfordJames Redford James.RedfordMichael Jackson Michael.JacksonJohn Brown John.BrownJohn Brown John.BrownJohn Brown John.BrownGeorge GothamI want to update duplicated values at ColumnC like:Alice Lukas Alice.LucasJames Redford James.RedfordJames Redford James.Redford1Michael Jackson Michael.JacksonJohn Brown John.BrownJohn Brown John.Brown1John Brown John.Brown2George GothamHow can i do it?Thanks in advance!Note: Table is for creating email aliases from names... |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-02-14 : 09:03:09
|
UPDATE fSET f.ColumnC = f.ColumnC + CAST(f.RecID - 1 AS VARCHAR)FROM (SELECT ColumnC, ROW_NUMBER() OVER (PARTITION BY COlumnA, COlumnB, ColumnC ORDER BY ColumnC) AS RecID) AS fWHERE f.RecID > 1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-14 : 09:04:18
|
TryUPDATE tSET t.ColumnC=t.ColumnC +CAST((t.RowNo -1) AS varchar(4))FROM (SELECT ROW_NUMBER() OVER(PARTITION BY ColumnA,ColumnB ORDER BY ColumnA,ColumnB) AS RowNo,ColumnA,ColumnB,ColumnCFROM Table)tWHERE t.RowNo <>1 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-14 : 09:22:05
|
Both are very fond of ROW_NUMBER() MadhivananFailing to plan is Planning to fail |
 |
|
|
LacOniC
Starting Member
29 Posts |
Posted - 2008-02-14 : 09:23:16
|
| I had a collation problem with these. Can't i do it by using only ColumnC? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-14 : 09:27:00
|
quote: Originally posted by LacOniC I had a collation problem with these. Can't i do it by using only ColumnC?
What is the error you are getting?MadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-02-14 : 09:28:16
|
[code]UPDATE fSET f.ColumnC = f.ColumnC + CAST(f.RecID - 1 AS VARCHAR(12))FROM ( SELECT ColumnC, ROW_NUMBER() OVER (PARTITION BY ColumnC ORDER BY ColumnC) AS RecID FROM Table1 ) AS fWHERE f.RecID > 1[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
LacOniC
Starting Member
29 Posts |
Posted - 2008-02-14 : 09:43:11
|
quote: Originally posted by madhivanan
quote: Originally posted by LacOniC I had a collation problem with these. Can't i do it by using only ColumnC?
What is the error you are getting?MadhivananFailing to plan is Planning to fail
ColumnA = AlI, ColumnB = ÖZTÜRK, ColumnC = ali.ozturkColumnA = AlI, ColumnB = ÖZTÜRK, ColumnC = ali.ozturkColumnA is different but ColumnC is same. So base column must be ColumnC. I didn't talk about it at startup, my mistake sorry. |
 |
|
|
LacOniC
Starting Member
29 Posts |
Posted - 2008-02-14 : 09:49:00
|
| Can't use that local letter here. Is's big "i". :P Above post seems wrong. |
 |
|
|
LacOniC
Starting Member
29 Posts |
Posted - 2008-02-14 : 10:00:06
|
quote: Originally posted by Peso
UPDATE fSET f.ColumnC = f.ColumnC + CAST(f.RecID - 1 AS VARCHAR(12))FROM ( SELECT ColumnC, ROW_NUMBER() OVER (PARTITION BY ColumnC ORDER BY ColumnC) AS RecID FROM Table1 ) AS fWHERE f.RecID > 1 E 12°55'05.25"N 56°04'39.16"
This worked very well. Thank both of you. |
 |
|
|
|