| Author |
Topic  |
|
|
kot
Starting Member
7 Posts |
Posted - 10/14/2005 : 13:50:15
|
Hi! I'd like to update a table's column with the value, that is a function of the row's number. Something like:
update MY_TABLE set RNUMBER=CurrentRow
Is anything like this possible? Thanks! |
|
|
anuj164
Starting Member
USA
49 Posts |
Posted - 10/14/2005 : 14:41:43
|
Yes can use it in this way
ALTER TABLE MY_TABLE ADD RNUMBER int NULL CONSTRAINT AddDateDflt_PageView identity (1,1) WITH VALUES
this will add a colums assign it as an identity field and will updates all the records with the auto incremnet value. |
 |
|
|
kot
Starting Member
7 Posts |
Posted - 10/14/2005 : 14:47:25
|
Thank you for your answer.
But what about some other function of the CurrentRow (CurrentRow*2 or CurrentRow-1)?
Also, I have the column already -- I just want to change its values in the fastest way possible... |
 |
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 10/14/2005 : 14:52:56
|
CurrentRow*2 would be identity (2,2) and CurrentRow-1 would be identity (0,1)
if my brain is in the right gear!
Kristen |
 |
|
|
anuj164
Starting Member
USA
49 Posts |
Posted - 10/14/2005 : 14:56:18
|
Oh I missunderstood your post sorry! you can update it by calling a UFD. update MY_TABLE set RNUMBER=myfun(2,3)
Anuj |
 |
|
|
anuj164
Starting Member
USA
49 Posts |
Posted - 10/14/2005 : 14:57:35
|
| Yes Kristen you are 100 % correct. |
 |
|
|
kot
Starting Member
7 Posts |
Posted - 10/14/2005 : 15:15:40
|
quote: Originally posted by anuj164 update MY_TABLE set RNUMBER=myfun(2,3)
Ok, and how will myfun look like? How can it access the current row's number? Is there anything like @@CURRENTROW?
Thanks! |
Edited by - kot on 10/14/2005 15:19:30 |
 |
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 10/15/2005 : 01:47:04
|
You probably need to create a temporary table, with an IDENTITY column and the PKs of your main table, INSERT the PKs from your Main Table (using an appropriate ORDER BY to get the Identities assigned in the right order), and then JOIN the temporary table to your main table for an Update to set the RNUMBER column to the appropriate new value
Kristen |
 |
|
|
TG
Flowing Fount of Yak Knowledge
USA
5467 Posts |
Posted - 10/15/2005 : 08:40:22
|
Hi kot,
<FeelFreeToIgnoreThis >
>>Also, I have the column already -- I just want to change its values in the fastest way possible... based on this statement and the other thread about the log: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56472
It sounds to me like you want to "re-sequence" a tables identity column values on a regular basis. It may be due to my limited imagination but I can't think of a good reason to do this. However depending on what this column is used for I can imagine reasons not to do it. Is this what you're doing? If so...why?
</FeelFreeToIgnoreThis >
Be One with the Optimizer TG |
 |
|
| |
Topic  |
|