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 |
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2010-03-25 : 17:17:21
|
| Hello, I have to update Field2, look at the output looks like.declare @tbl1 table (ID INT,Field1 varchar(20),Field2 varchar(10))INSERT INTO @tbl1SELECT 1, 'AAA',nullINSERT INTO @tbl1SELECT 2,'AAA', nullINSERT INTO @tbl1SELECT 3,'AAA', nullINSERT INTO @tbl1SELECT 4, 'BBB',nullINSERT INTO @tbl1SELECT 5,'BBB', nullINSERT INTO @tbl1SELECT 6,'CCC', nullINSERT INTO @tbl1SELECT 7,'CCC', nullselect * from @tbl1Out Put :ID Field1 Field21 AAA 10012 AAA 10023 AAA 10034 BBB 10015 BBB 10026 CCC 10017 CCC 1002 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-25 : 18:30:06
|
[code]update tset Field2 = convert(varchar(10), 1000 + row_no)from ( select ID, Field1, Field2, row_no = row_number() over (partition by Field1 order by ID) from @tbl1 ) t[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-26 : 02:29:24
|
| I suggest you to do it when you display data using SELECT statementOtherwise you need to run updates as soon as new data are addedMadhivananFailing to plan is Planning to fail |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-03-26 : 02:55:03
|
| And if permanently you want to update then you should also make the same logic at the time of insert i think.Vaibhav T |
 |
|
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2010-03-26 : 09:19:22
|
| Thanks it works. |
 |
|
|
|
|
|
|
|