SQL2008R2  ORDER BYnot working

FrankLu
FrankLu used Ask the Experts™
on
Hi All,
I installed over the weekend SQL 2008R2 Express. I imported a table tblabbreviations (ID, Abbreviation (nvarchar(10), Description Nvarchar(50).
Afterwards I added some records and created a new Query
SELECT * from dbo.tblAbbreviations
ORDER BY Abbreviation
Problem:In the rsult Nothing is sorted.
If I enter in the blank table new records via (Access Frontend)then ORDER By works fine for these records , but not when some others were imported.

I looked already on the internet and some sources say to run SQL Server Compatibility Level SQL Server 2000(80). But this did not work too.

Appreciatate any help.

Thanks in advance
Best regrads
Frank
 
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I'm guessing the sort by really is working.  You are probably being deceived by some invisible leading spaces.  Try this to prove me wrong:

SELECT replace(abbreviation,' ','*') from dbo.tblAbbreviations
ORDER BY trim(Abbreviation)

Author

Commented:
Hi Dqmq, thanks for your qick reply. I'm quite new to SQL Server. But I got an error on the fact using trim. How do you want me to implement your comment ?
Thanks in advance
Frank

Author

Commented:
Hi DQMQ,

Indeed there is a blank space in some records which I could not see at first sight.
I adapted with trim and it works fine.
Thanks for your support
Best regards
Frank

Author

Commented:
I could not see that ther was a blank space as first character. Thanks
Frank
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
it would be rtrim() and/or ltrim() ... sql server does not have trim() ...

and you need to clarify with data samples of what you see "wrong results".
likely, your field is varchar, containing numerical data, and it sorts by design on varchar data, and not the "numerical data" ...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial