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 |
AnurRS
Starting Member
2 Posts |
Posted - 2012-06-25 : 22:22:43
|
Can we bulk update the records of the same table.I have a table structure like this.Table Name : MyTableSeqID Name SortNo1 Test1 0 2 Test2 13 Test3 2 4 Test4 05 Test5 16 Test6 27 Test7 3SeqID : Unique Auto generate columnName : Any arbitary nameSortNo : Index order in which the name is to be shownFrom my code i get all the list and with some logic, i regenerate all the sort numbers again which should be unique.lets say my required output isSeqID Name SortNo1 Test1 0 2 Test2 13 Test3 2 4 Test4 35 Test5 46 Test6 57 Test7 6---How can i update all the sort no value in the table . Do i need to loop each record and update ? Or can i first update all the records and then finally commit the updated transaction.Best RegardsAnur |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
AnurRS
Starting Member
2 Posts |
Posted - 2012-06-26 : 00:20:09
|
Tara Kizer ..Thanks for the reply and concern.SortNo as mentioned is the index or the order according to which the Name column is to be displayed in the front end GUI list view.For further detail info, i have one more column as Value .The work i need to do is like this..Originally let Database name : DatabaseVer1 MyTable has only these dataSeqID Name SortNo Value1 Test1 0 22 Test2 1 43 Test3 2 6 Then from one more similar table of database named : DatabaseVer2 , there is similar table MyTable with the data as followsSeqID Name SortNo Value1 Test4 0 82 Test5 1 103 Test6 2 124 Test7 3 14Now i need to copy the data from databaseVer1 MyTable to DatabaseVer2 MyTable. With some merging logic i have copied the data whose result is shown in the above post.SeqID Name SortNo Value1 Test1 0 22 Test2 1 43 Test3 2 64 Test4 0 85 Test5 1 106 Test6 2 127 Test7 3 14After merging data, i once again retrived all those data and on the basis of Value column, i once again calculated the new SortNo. with some sorting algorithm. After getting the desired sortNo values, i want to now update this value in the table. So, can i do the update in bulk or do i need to carry out the update for each record row.Best Regards |
|
|
|
|
|