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)
 Strange behaviour

Author  Topic 

Rita Bhatnagar
Posting Yak Master

172 Posts

Posted - 2002-03-08 : 13:33:57
If i write the statement like that i don't get result in any order
SELECT DISTINCT Left(awp.tradename,1) AS Lett
FROM AWP
But when i use the statement below i get result in ascending order

SELECT DISTINCT Left(awp.tradename,1) AS Lett
FROM AWP where Left(awp.tradename,1)<>''

What's going on?

setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2002-03-08 : 13:53:31
without an ORDER BY, the order of the rowset is indeterminate. It may be "ordered" in some fashion today, but it can change as SQL Server shuffles pages around due to deletes, clustered index changes, etc.

Don't rely on it, use ORDER BY explicitly.

Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2002-03-08 : 13:54:59
doing a <>'' will order as it takes into account any indexes on the table, run a trace or query plan and you will see this...

Go to Top of Page
   

- Advertisement -