从MySql移植到T-Sql.任何等效的INET_ATON()吗? [英] Porting from MySql to T-Sql. Any INET_ATON() equivalent?

查看:76
本文介绍了从MySql移植到T-Sql.任何等效的INET_ATON()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要将一些代码从MySql移到TSql.我对INET_ATON进行了两次调用,该调用将类似于IPAddress的字符串转换为数字.是否有等效的T-SQL?

Need to move some code from MySql to TSql. I have a couple of calls to INET_ATON which converts a string which resembles an IPAddress into a number. Is there a T-SQL equivalent?

推荐答案

parsname函数的滥用:

An abuse of the parsname function:

create function INET_ATON (@addr varchar(15))
returns bigint
with schemabinding
as
begin
  return  
    cast(parsename(@addr, 4) as bigint) * 16777216 +
    cast(parsename(@addr, 3) as bigint) * 65536 +
    cast(parsename(@addr, 2) as bigint) * 256 +
    cast(parsename(@addr, 1) as bigint)
end

尽管这里不支持简式地址".

That "short form address" thing is not supported here though.

这篇关于从MySql移植到T-Sql.任何等效的INET_ATON()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆