Gossamer Forum
Home : General : Databases and SQL :

Update needs an order by... what to do

Quote Reply
Update needs an order by... what to do
I need to update a table's sort column so that I can alphabetize the list. Here's the data and what I tried:

select * from var_category order by data_desc

Gives:

data_id data_desc data_sort data_status
--------- ----------------------- ----------- -----------
9 AAAAA 9 1
7 EEEEEE 7 1
1 FFFFFF 1 1
2 MMMMM 2 1
3 OOOOO 3 1
6 PPPPPP 6 1
10 SSSSSA 10 1
4 SSSSSS 4 1
5 TTTTTT 5 1
8 VVVVVV 8 1

and I want to do this:

declare @mycount tinyint
select @mycount = 0
update var_category set data_sort = (select @mycount = @mycount + 1) order by data_desc


..but update doesn't have an order by. You can't create views with order...

I guess I could move it to a temp table and swap it back, but I need to do this to several large tables. Any ideas would be helpful.

Thanks!
Subject Author Views Date
Thread; hot thread Update needs an order by... what to do pepsiwave 16597 Mar 6, 2003, 11:18 AM
Thread; hot thread Re: [pepsiwave] Update needs an order by... what to do
Paul 16360 Mar 6, 2003, 11:30 AM
Thread; hot thread Re: [Paul] Update needs an order by... what to do
pepsiwave 16299 Mar 6, 2003, 11:37 AM
Thread; hot thread Re: [pepsiwave] Update needs an order by... what to do
Paul 16342 Mar 6, 2003, 11:40 AM
Thread; hot thread Re: [Paul] Update needs an order by... what to do
pepsiwave 16356 Mar 6, 2003, 11:45 AM
Thread; hot thread Re: [pepsiwave] Update needs an order by... what to do
Paul 16346 Mar 6, 2003, 11:48 AM
Thread; hot thread Re: [Paul] Update needs an order by... what to do
pepsiwave 16350 Mar 6, 2003, 11:50 AM
Thread; hot thread Re: [pepsiwave] Update needs an order by... what to do
Paul 16315 Mar 6, 2003, 11:58 AM
Thread; hot thread Re: [Paul] Update needs an order by... what to do
pepsiwave 16291 Mar 6, 2003, 12:07 PM
Post; hot thread Re: [pepsiwave] Update needs an order by... what to do
Paul 16260 Mar 6, 2003, 12:09 PM
Post; hot thread Re: [pepsiwave] Update needs an order by... what to do
Alex 16256 Mar 6, 2003, 12:29 PM
Post; hot thread Re: [pepsiwave] Update needs an order by... what to do
kris kf 15784 Dec 3, 2003, 11:46 PM