Donatello Cruz
2012-03-16 02:08:08 UTC
Hi All,
I've got a column in the database that has IP addresses, though the
column data might have multiple IPs, comma separated that take the
form of: 192.168.1.1,192.168.1.3,192.168.1.5
All I want to extract is the first IP address using a CASE statement:
Select
Case When substring(o2.String4, 1, charindex(',', o2.string4)) = ','
Then substring(o2.String4, 1, 12)
Else o2.string4
End as [IP Address]
However, I keep getting all the IPs (when present for each row).
Any help is appreciated!
I've got a column in the database that has IP addresses, though the
column data might have multiple IPs, comma separated that take the
form of: 192.168.1.1,192.168.1.3,192.168.1.5
All I want to extract is the first IP address using a CASE statement:
Select
Case When substring(o2.String4, 1, charindex(',', o2.string4)) = ','
Then substring(o2.String4, 1, 12)
Else o2.string4
End as [IP Address]
However, I keep getting all the IPs (when present for each row).
Any help is appreciated!