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 |
kot
Starting Member
7 Posts |
Posted - 2005-10-14 : 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=CurrentRowIs anything like this possible? Thanks! |
|
anuj164
Starting Member
49 Posts |
Posted - 2005-10-14 : 14:41:43
|
Yes can use it in this way ALTER TABLE MY_TABLEADD RNUMBER int NULLCONSTRAINT AddDateDflt_PageViewidentity (1,1) WITH VALUESthis 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 - 2005-10-14 : 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
22859 Posts |
Posted - 2005-10-14 : 14:52:56
|
CurrentRow*2 would be identity (2,2)andCurrentRow-1 would be identity (0,1)if my brain is in the right gear!Kristen |
|
|
anuj164
Starting Member
49 Posts |
Posted - 2005-10-14 : 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
49 Posts |
Posted - 2005-10-14 : 14:57:35
|
Yes Kristen you are 100 % correct. |
|
|
kot
Starting Member
7 Posts |
Posted - 2005-10-14 : 15:15:40
|
quote: Originally posted by anuj164update 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! |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-10-15 : 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 valueKristen |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-10-15 : 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=56472It 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 OptimizerTG |
|
|
|
|
|
|
|