Porting from MySql to T-Sql. Any INET_ATON() equivalent?

前端 未结 4 877
名媛妹妹
名媛妹妹 2020-12-10 18:16

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 equival

4条回答
  •  再見小時候
    2020-12-10 18:34

    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.

提交回复
热议问题