Splitting string using sql statement (ip address)

前端 未结 2 528
隐瞒了意图╮
隐瞒了意图╮ 2021-01-29 15:38

I need to split ip address in sql.

I have done lots of finding but could not find any builtin method that do the task.

How can I accomplish this task?

I

2条回答
  •  时光说笑
    2021-01-29 16:18

    You can use PARSENAME function as following :

    with address as(
    select '192.168.1.1' as IpAddress
    Union
    select '192.168.1.2' as IpAddress
    Union
    select '192.168.1.3' as IpAddress
    )
    SELECT PARSENAME(IpAddress,4) as first, 
       PARSENAME(IpAddress,3) as second,
       PARSENAME(IpAddress,2) as third,
       PARSENAME(IpAddress,1) as fourth,
    FROM address
    

    PARSENAME function returns the specified part of an object name.

提交回复
热议问题