Create function fnMaxAddress(@value varchar(max)) returns @result table
(
ip varchar(30),
mac_address varchar(30)
)
as
begin
declare @index int
declare @ip varchar(max)
set @index = CHARINDEX('dvc=',@value)
set @ip= ltrim(substring(@value,@index+4,len(@value)))
insert into @result
select substring(@ip,1,CHARINDEX(' ',@ip)),
ltrim(replace(substring(@ip,CHARINDEX(' ',@ip),len(@ip)),'deviceMacAddress=',''))
return
end;
Create function fnMaxAddress(@value varchar(max)) returns @result table
(
ip varchar(30),
mac_address varchar(30)
)
as
begin
declare @index int
declare @ip varchar(max)
set @index = CHARINDEX('dvc=',@value)
set @ip= ltrim(substring(@value,@index+4,len(@value)))
insert into @result
select substring(@ip,1,CHARINDEX(' ',@ip)),
ltrim(replace(substring(@ip,CHARINDEX(' ',@ip),len(@ip)),'deviceMacAddress=',''))
return
end;
Code
insert into macaddress SELECT s.ip,s.mac_address FROM syslogd AS t CROSS APPLY dbo.fnMaxAddress(t.MsgText) AS s;