SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 UPDATE-ing with CurrentRow
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kot
Starting Member

7 Posts

Posted - 10/14/2005 :  13:50:15  Show Profile  Send kot an AOL message  Send kot a Yahoo! Message  Reply with Quote
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  Show Profile  Send anuj164 a Yahoo! Message  Reply with Quote
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.
Go to Top of Page

kot
Starting Member

7 Posts

Posted - 10/14/2005 :  14:47:25  Show Profile  Send kot an AOL message  Send kot a Yahoo! Message  Reply with Quote
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...
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 10/14/2005 :  14:52:56  Show Profile  Reply with Quote
CurrentRow*2 would be identity (2,2)
and
CurrentRow-1 would be identity (0,1)

if my brain is in the right gear!

Kristen
Go to Top of Page

anuj164
Starting Member

USA
49 Posts

Posted - 10/14/2005 :  14:56:18  Show Profile  Send anuj164 a Yahoo! Message  Reply with Quote
Oh I missunderstood your post sorry!
you can update it by calling a UFD.
update MY_TABLE set RNUMBER=myfun(2,3)

Anuj
Go to Top of Page

anuj164
Starting Member

USA
49 Posts

Posted - 10/14/2005 :  14:57:35  Show Profile  Send anuj164 a Yahoo! Message  Reply with Quote
Yes Kristen you are 100 % correct.
Go to Top of Page

kot
Starting Member

7 Posts

Posted - 10/14/2005 :  15:15:40  Show Profile  Send kot an AOL message  Send kot a Yahoo! Message  Reply with Quote
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
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 10/15/2005 :  01:47:04  Show Profile  Reply with Quote
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
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
6059 Posts

Posted - 10/15/2005 :  08:40:22  Show Profile  Reply with Quote
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000