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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 populating a varible with multiple rows of data.

Author  Topic 

jose1024
Starting Member

5 Posts

Posted - 2004-10-12 : 15:42:43
I need to populate a variable with data from a table. Now here's the thing: the variable needs to populated with let's say row 1 column 10, then it performs some calculations and the result is placed on the same table in a different colummn, I'll call "results". Once it has done this, it needs to go to the next row column 10 and start the process all over until the entire table is processed. I am currently using cursors with the fetch next to scroll through the table, but it seems awfully slow. Is there a more efficient way to scroll and populate my variables?

Thanks

Chester
Starting Member

27 Posts

Posted - 2004-10-12 : 16:07:17
I think this will do but you need a column that makes each record unique like a record id.

update table set results = (select the_number*5 [whatever your calculation is here]
from table t2 where table.rec_id = t2.rec_id)
Go to Top of Page

hgorijal
Constraint Violating Yak Guru

277 Posts

Posted - 2004-10-13 : 05:39:58
quote:
Originally posted by jose1024

the variable needs to populated with let's say row 1 column 10, then it performs some calculations and the result is placed on the same table in a different colummn, I'll call "results".


same table ?: Did you mean the same row ?

meaning : perform calculation on "column 1" of "row 1" and update the "result" in "row 1". ...And do this for entire table..

does this not work...

UPDATE TABLE SET results = calculation(col_1)

I don't see any requirement to "populating a varible with multiple rows of data"


Hemanth Gorijala
BI Architect / DBA...

Exchange a Dollar, we still have one each.
Exchange an idea, we have TWO each.
Go to Top of Page
   

- Advertisement -