# IP地址列的排序

功能是实现了，不过比较繁琐不知还有什么简单的方法！？

SELECT PublicIp, LEFT(PublicIp, CASE WHEN CHARINDEX('.', PublicIp)
<= 0 THEN 0 ELSE CHARINDEX('.', PublicIp) - 1 END) AS ip1,

LEFT(STUFF(PublicIp, 1, CHARINDEX('.', PublicIp),''), CASE WHEN CHARINDEX('.', STUFF(PublicIp, 1, CHARINDEX('.', PublicIp),''))
<= 0 THEN 0 ELSE CHARINDEX('.', STUFF(PublicIp, 1, CHARINDEX('.', PublicIp),'')) - 1 END) AS ip2,

LEFT(STUFF(STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), ''), 1,   CHARINDEX('.', STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), '')), ''), CASE WHEN CHARINDEX('.', STUFF(STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), ''), 1,   CHARINDEX('.', STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), '')), '')) <= 0 THEN 0 ELSE CHARINDEX('.', STUFF(STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), ''), 1,   CHARINDEX('.', STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), '')), '')) - 1 END) AS ip3,

CASE WHEN (STUFF(STUFF(STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), ''), 1,   CHARINDEX('.', STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), '')), ''), 1,   CHARINDEX('.', STUFF(STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), ''), 1,   CHARINDEX('.', STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), '')), '')), '')= NULL) then 0 else cast(STUFF(STUFF(STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), ''), 1,   CHARINDEX('.', STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), '')), ''), 1,   CHARINDEX('.', STUFF(STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), ''), 1,   CHARINDEX('.', STUFF(PublicIp, 1,   CHARINDEX('.', PublicIp), '')), '')), '') as int) end AS ip4

FROM ServerInfo order by ip1 ,ip2, ip3 ,ip4