Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sorting

Author  Topic 

stumbling
Posting Yak Master

104 Posts

Posted - 2008-09-09 : 05:55:06
Hi ALL
I have a column that is full of IP addresses that i need to sort from highest to lowest the problem is sort can not get them in to the correct order as per below any one have any ideas on this?
Cheers
192.168.32.147
192.168.32.147
192.168.32.148
192.168.32.149
192.168.32.15
192.168.32.150
192.168.32.151
192.168.32.152
192.168.32.153
192.168.32.154
192.168.32.156
192.168.32.157
192.168.32.158
192.168.32.159
192.168.32.16
192.168.32.16
192.168.32.160

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-09-09 : 06:04:35
Read links given below in order.

http://weblogs.sqlteam.com/jeffs/archive/2008/01/17/60458.aspx
http://www.sql-server-helper.com/tips/sort-ip-address.aspx


Go to Top of Page

stumbling
Posting Yak Master

104 Posts

Posted - 2008-09-09 : 06:15:31
Thanks for that i found this which works for me :- ))
SELECT [IPAddress] FROM [WorkStation]
ORDER BY CAST(PARSENAME([IPAddress], 4) AS INT),
CAST(PARSENAME([IPAddress], 3) AS INT),
CAST(PARSENAME([IPAddress], 2) AS INT),
CAST(PARSENAME([IPAddress], 1) AS INT)
Go to Top of Page
   

- Advertisement -