dbTalk Databases Forums  

SQL: numeric sort of a varchar field

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss SQL: numeric sort of a varchar field in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
 
Posts: n/a

Default SQL: numeric sort of a varchar field - 01-22-2008 , 05:15 AM






Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?

thank you for your help.

ELE.

EG. sort a list of bus lines

1
14
2
23
3
4
44
5

must be

1
2
3
4
5
14
23
44






Reply With Quote
  #2  
Old   
Paul Shapiro
 
Posts: n/a

Default Re: numeric sort of a varchar field - 01-22-2008 , 05:56 AM






Use Order By Cast(columnName as int), as long as all values are legitimate
integers. But if so, why not make the column datatype int?

<eric.lecocq (AT) toto (DOT) com> wrote

Quote:
Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?


Reply With Quote
  #3  
Old   
Paul Shapiro
 
Posts: n/a

Default Re: numeric sort of a varchar field - 01-22-2008 , 05:56 AM



Use Order By Cast(columnName as int), as long as all values are legitimate
integers. But if so, why not make the column datatype int?

<eric.lecocq (AT) toto (DOT) com> wrote

Quote:
Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?


Reply With Quote
  #4  
Old   
Paul Shapiro
 
Posts: n/a

Default Re: numeric sort of a varchar field - 01-22-2008 , 05:56 AM



Use Order By Cast(columnName as int), as long as all values are legitimate
integers. But if so, why not make the column datatype int?

<eric.lecocq (AT) toto (DOT) com> wrote

Quote:
Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?


Reply With Quote
  #5  
Old   
Paul Shapiro
 
Posts: n/a

Default Re: numeric sort of a varchar field - 01-22-2008 , 05:56 AM



Use Order By Cast(columnName as int), as long as all values are legitimate
integers. But if so, why not make the column datatype int?

<eric.lecocq (AT) toto (DOT) com> wrote

Quote:
Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?


Reply With Quote
  #6  
Old   
Paul Shapiro
 
Posts: n/a

Default Re: numeric sort of a varchar field - 01-22-2008 , 05:56 AM



Use Order By Cast(columnName as int), as long as all values are legitimate
integers. But if so, why not make the column datatype int?

<eric.lecocq (AT) toto (DOT) com> wrote

Quote:
Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?


Reply With Quote
  #7  
Old   
Paul Shapiro
 
Posts: n/a

Default Re: numeric sort of a varchar field - 01-22-2008 , 05:56 AM



Use Order By Cast(columnName as int), as long as all values are legitimate
integers. But if so, why not make the column datatype int?

<eric.lecocq (AT) toto (DOT) com> wrote

Quote:
Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?


Reply With Quote
  #8  
Old   
Paul Shapiro
 
Posts: n/a

Default Re: numeric sort of a varchar field - 01-22-2008 , 05:56 AM



Use Order By Cast(columnName as int), as long as all values are legitimate
integers. But if so, why not make the column datatype int?

<eric.lecocq (AT) toto (DOT) com> wrote

Quote:
Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?


Reply With Quote
  #9  
Old   
Paul Shapiro
 
Posts: n/a

Default Re: numeric sort of a varchar field - 01-22-2008 , 05:56 AM



Use Order By Cast(columnName as int), as long as all values are legitimate
integers. But if so, why not make the column datatype int?

<eric.lecocq (AT) toto (DOT) com> wrote

Quote:
Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?


Reply With Quote
  #10  
Old   
Paul Shapiro
 
Posts: n/a

Default Re: numeric sort of a varchar field - 01-22-2008 , 05:56 AM



Use Order By Cast(columnName as int), as long as all values are legitimate
integers. But if so, why not make the column datatype int?

<eric.lecocq (AT) toto (DOT) com> wrote

Quote:
Hello Everybody,

my question is the following. how can sort numerically a sql query with
varchar field ?


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.