Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

order by ip address 1

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
I have a varchar field that holds ip addresses... how can I get this to order properly. Like say I have these five values:

10.650.555.101
10.650.555.11
10.650.555.105
10.650.555.12
10.650.555.124

simply doing an order by on this field now, it returns:

10.650.555.101
10.650.555.105
10.650.555.11
10.650.555.12
10.650.555.124

and I want it to return:

10.650.555.11
10.650.555.12
10.650.555.101
10.650.555.105
10.650.555.124

How could I get this?

[conehead]
 
create table ip(IP varchar(50))
insert into ip
select '10.650.555.101'
union all
select '10.650.555.11'
union all
select '10.650.555.105'
union all
select '10.650.555.12'
union all
select '10.650.555.124'

select * from ip
order by convert(bigint,replace(ip,'.',''))

“I sense many useless updates in you... Useless updates lead to defragmentation... Defragmentation leads to downtime...Downtime leads to suffering..Defragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top