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)
 INDEX CONTROL

Author  Topic 

JERICHO
Starting Member

18 Posts

Posted - 2002-10-08 : 23:16:30
hey, is there any way that i can control the index ordering.

say now i am control the way my data is being sort by inserting this clustered index

create clustered index order
on tbl_1 (custid desc)
go

ok but with my table my values for custid is as follow

Custid

aaron
boy
cat
dog
others

if there anyway i can control the index and sort it in a way that others will always be the last ?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-10-08 : 23:29:35
It really doesn't matter if you store the rows in descending order, you can use a CASE expression in the ORDER BY clause to order them:

SELECT * FROM tbl_1
ORDER BY CASE CustID WHEN 'others' THEN 1 ELSE 0 END,
CustID


Remember, if you want to SELECT rows in a particular order, you MUST use an ORDER BY clause. You WILL NOT get reliable sorting without it, no matter what you do with the indexing.

Go to Top of Page

JERICHO
Starting Member

18 Posts

Posted - 2002-10-08 : 23:43:59
It is not really a select statement because i am using another tool to disply my information from the db so is there an alternative?

Go to Top of Page

JERICHO
Starting Member

18 Posts

Posted - 2002-10-08 : 23:44:33
It is not really a select statement because i am using another tool to disply my information from the db so is there an alternative?

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-10-09 : 09:01:55
What tool are you using? The fact remains that SQL Server returns rows using a SELECT statement, regardless of how the interface is designed or implemented. If that tool doesn't allow you to specify a sort order, or supply customized SQL statements, you should use something else.

Go to Top of Page
   

- Advertisement -