Re: how to order by string data type that is actually numeric?

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Dejan Sarka (dejan_please_reply_to_newsgroups.sarka_at_avtenta.si)
Date: 08/23/04


Date: Mon, 23 Aug 2004 08:01:48 +0200

Use CAST function:
SELECT *
 FROM TestTable
ORDER BY CAST(sortstring AS bigint)

-- 
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Bobby" <bobby.saputra@epselindo.com> wrote in message
news:ueL4z5LiEHA.1652@TK2MSFTNGP09.phx.gbl...
> Hi...
> I just curios about this.
> I have 1 tabel 'tbl1' and 1 column 'col1' as string
>
> Col1
> 110
> 21
> 2
>
>
> query --> "select * from tbl1 order by col1"
> result:
> Col1
> 1
> 10
> 2
> 21
>
> Question: Can I order the data as numeric, not as string? How?
>
> I want to get result
> Data
> Col1
> 1
> 2
> 10
> 21
>
> Thanks
>
>


Relevant Pages

  • Re: best way to scrub data
    ... Dejan Sarka, SQL Server MVP ... This message does not imply endorsement from Solid Quality Learning, ... > sensitive data like user info,credit card info,etc.. ...
    (microsoft.public.sqlserver.security)
  • Re: clearing concept
    ... and Extents" chapter. ... >> Dejan Sarka, SQL Server MVP ... >> Solid Quality Learning ...
    (microsoft.public.sqlserver.clients)
  • Re: Change sql agent login user
    ... Dejan Sarka, SQL Server MVP ... Solid Quality Learning ... "shivi" wrote in message ...
    (microsoft.public.sqlserver.security)
  • Re: predetermine size of differential
    ... You can try with the undocumented DBCC PAGE command - see ... Dejan Sarka, SQL Server MVP ... Solid Quality Learning ...
    (microsoft.public.sqlserver.server)
  • Re: switching from CAL to Processor license
    ... thank you soooooo much for your response - you can't imagine how much work ... You're right the MS knowledge base didn't help but your ... > Dejan Sarka, SQL Server MVP ...
    (microsoft.public.sqlserver.setup)