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
 SQL Server Development (2000)
 update table's sort field alphabetically

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2006-10-25 : 12:07:21
Greetings,

My table has word definitions in them, and I am grouping them by letters (A,B,C) and I want to order the words alphabetically also.

LetterID represents A, B, C with numbers: 1, 2, 3. So A=1, B=2, etc.

Table1:

WordID Word LetterID SortOrder
23 Car 3 0
24 Bat 2 0
25 Bee 2 0


So I want to update the 'SortOrder' field so I can do a query to grab all the definitions that begin with 'B' like:

SELECT * FROM Table1 WHERE LetterID = 2 ORDER BY SortOrder

X002548
Not Just a Number

15586 Posts

Posted - 2006-10-25 : 12:09:40
Huh?

How about ORDER BY Word?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-10-25 : 12:18:08
update t
set SortOrder = (select count(*) from table1 where t.letterID = letterID and t.word < word)
from table1 t

Jay White
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2006-10-25 : 12:19:42
thanks page!

X002548: Yeah I can do that also, but the table actually has other rows in it and I don't really want to add an index on the 'word' field.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-10-25 : 13:49:15
quote:
Originally posted by sql777

thanks page!

X002548: Yeah I can do that also, but the table actually has other rows in it and I don't really want to add an index on the 'word' field.


You don't need an index on a column to order by it.





CODO ERGO SUM
Go to Top of Page
   

- Advertisement -