sql server - SQL Query to bring back fields that only contain numbers (specifically an IP address) -


i have quite few tables field called company can either have in them:

"fake company" or "5.5.5.5"

the numerical address above of course being ip address.

i'm not sure how i'd go writing select query brings rows have ip address in them , not text. ideas?

you use regularexpressions on sql-server, example:

insert tip values('fake company'); insert tip values('5.5.5.5'); insert tip values('192.168.5.8'); insert tip values('192.168.5.88');  declare @regexpattern varchar(100); set @regexpattern='([0-9]{1,3}\.|\*\.){3}([0-9]{1,3}|\*){1}';  select * tip  dbo.regexmatch( tip.ip, @regexpattern ) = 1 

and here function:

create function [dbo].[regexmatch](@input [nvarchar](4000), @pattern [nvarchar](4000)) returns [bit] execute caller  external name [regexlib].[regexlib.userdefinedfunctions].[regexmatch] 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -