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]
- regularexpressions on sql-server: http://msdn.microsoft.com/en-us/magazine/cc163473.aspx
- how integrate .net assemblies in sql-server: http://www.codeproject.com/kb/database/dotnetassembliesinmssql.aspx?display=mobile
Comments
Post a Comment