Groups | Blog | Home
all groups > sql server programming > august 2004 >

sql server programming : how to order by string data type that is actually numeric?


Bobby
8/22/2004 10:34:06 PM
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

Dejan Sarka
8/23/2004 8:01:48 AM
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

[quoted text, click to view]

Bobby
8/23/2004 1:19:19 PM
Thanks for your help.

"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@avtenta.si> wrote in
message news:O5zfvaNiEHA.1356@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button