Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Strange sorting

 
   Database Help (Home) -> MSDE RSS
Next:  Table Relationship issue.  
Author Message
Peter Herijgers

External


Since: Nov 19, 2008
Posts: 1



(Msg. 1) Posted: Wed Nov 19, 2008 11:25 am
Post subject: Strange sorting
Archived from groups: microsoft>public>sqlserver>msde (more info?)

Hi All,

Currently I am using MSDE.
If I want to order some items the output makes no sense to me.

I have a table with 3 records.
Each record has a column (varchar data type), which holds 1, 880 and 2200.

Using SELECT SomeField FROM MyTable ORDER BY SomeField
The records are sorted like this 1, 2200, 880.

I can overcome this problem by using this
SELECT CAST(ItemNo AS int) FROM MyTable ORDER BY CAST(ItemNo AS int)

Any ideas why the first SQL Query is not working?

Is this a known problem of MSDE?
Later this year I want to upgrade to SQL 2008.

Thanks in advance.

Peter

 >> Stay informed about: Strange sorting 
Back to top
Login to vote
"William Vaughn

External


Since: Jul 06, 2008
Posts: 35



(Msg. 2) Posted: Thu Nov 20, 2008 1:03 pm
Post subject: Re: Strange sorting [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

This is 100% understandable. How would you sort the following list? A, F, C,
B
Since you recognize these as letters you (and SQL Server) know how to sort
them. However if you ask SQL Server to sort character fields that happen to
contain numbers it does the same thing so 2200 comes after 1 and 8 comes
after 2200.
If the column is supposed to store (only) numbers, cast it as a numeric
type. This will help SQL Server sort it as a number. Otherwise you have to
cast (which will hurt performance).

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________



"Peter Herijgers" wrote in message

> Hi All,
>
> Currently I am using MSDE.
> If I want to order some items the output makes no sense to me.
>
> I have a table with 3 records.
> Each record has a column (varchar data type), which holds 1, 880 and 2200.
>
> Using SELECT SomeField FROM MyTable ORDER BY SomeField The records are
> sorted like this 1, 2200, 880.
>
> I can overcome this problem by using this SELECT CAST(ItemNo AS int) FROM
> MyTable ORDER BY CAST(ItemNo AS int)
>
> Any ideas why the first SQL Query is not working?
>
> Is this a known problem of MSDE?
> Later this year I want to upgrade to SQL 2008.
>
> Thanks in advance.
>
> Peter

 >> Stay informed about: Strange sorting 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Install MSDE in XP - Hi all, I have a problem with MSDE installation. Here is the last part of error log. === Logging stopped: 10/10/2003 17:49:00 === MSI (c) (44:64): Note: 1: 1708 MSI (c) (44:64): Product: Microsoft SQL Server Desktop Engine -- Installation operation...

Clone SQL DB (using VB?) - Hi all, I'm having a SQL Server database called X. For testing and training, I would like to make a copy of the entire DB to Y. This copy should include all data, properties, indexes, views, etc. Unfortunately, all my attempts to automate this..

Pubs and Northwind - I have MSDE 2000 installed but don't know how to connect to pubs or northwind. Could anyone help? Running Svr 03

Password in SQL - Hi, Is there a way I can store password in SQL table as encrypted using SQL table defintion instead of writing code to do encrypt and decrypt? Thanks.

I'm running Svr 03... - How do I get MSDE with Pubs and Northwind installed on this os
   Database Help (Home) -> MSDE All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]