I'm creating a web-based NT RAS report site and am looking for the most efficient way to import the data from NT Event log into SQL2k while formatting the data properly. I'm using the 'dumpel' utility from rsc kit and all is fine except the 10th column - the message detail:
"The user DOMAIN\userid connected on port Mdm15 on 08/23/2002 at 07:25am and disconnected on 08/23/2002 at 07:27am. The user was active for 2 minutes 23 seconds. 78809 bytes were sent and 50675 bytes were received. The port speed was 49300."
I need to parse this one long text string into 6 distinct columns: userID, port, duration, bytes_xmt, bytes_rcv and portspeed. Afterwards I'd like to have these values inserted into a new table.
Here's where I'm at with the example string (thanks to other forum notes):
==================================================
--declare string variables
declare @mystring varchar(1000)
declare @length int
declare @len1 int
declare @len2 int
set @mystring = 'The user DOMAIN\userid connected on port Mdm15 on 08/23/2002 at 07:25am and disconnected on
08/23/2002 at 07:27am. The user was active for 2 minutes 23 seconds. 78809 bytes were sent and 50675 bytes were received. The port speed was 49300.'
set @length = len(@mystring)
--print UserID
set @len1 = charindex('user',@mystring,1)
set @len2 = charindex('connected',@mystring,@len1)
print 'UserID:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'user','')))
--print Port Number
set @len1 = charindex('port',@mystring,1)
set @len2 = charindex('on',@mystring,(@len1))
print 'Port Number:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'port','')))
--Print Duration
set @len1 = charindex('user was active for ',@mystring,1)
set @len2 = charindex('.',@mystring,(@len1))
print 'Duration:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'user was active for','')))
--Print Bytes Sent
set @len1 = charindex('. ',@mystring,@len1)
set @len2 = charindex(' bytes',@mystring,(@len1))
print 'Bytes Sent:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'. ','')))
--Print Bytes Received
set @len1 = charindex('were sent and ',@mystring,@len1)
set @len2 = charindex(' bytes',@mystring,(@len1))
print 'Bytes Rcv:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1-1),'were sent and','')))
--Print Port Speed
set @len1 = charindex('port speed was',@mystring,@len1)
set @len2 = charindex('.',@mystring,(@len1))
print 'Port Speed:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'port speed was','')))
=====================================================
The above code returns the necessary values and now I need to insert these into a new table along with a few other columns from the event dump (date, time, servername). I've heard of using cursors to aid in the extraction and insert, but most forum entries advise not to use cursors for fear of performance degradation issues. Any thoughts?? Any help or script notes would be very appreciated
TIA
-Greg
"The user DOMAIN\userid connected on port Mdm15 on 08/23/2002 at 07:25am and disconnected on 08/23/2002 at 07:27am. The user was active for 2 minutes 23 seconds. 78809 bytes were sent and 50675 bytes were received. The port speed was 49300."
I need to parse this one long text string into 6 distinct columns: userID, port, duration, bytes_xmt, bytes_rcv and portspeed. Afterwards I'd like to have these values inserted into a new table.
Here's where I'm at with the example string (thanks to other forum notes):
==================================================
--declare string variables
declare @mystring varchar(1000)
declare @length int
declare @len1 int
declare @len2 int
set @mystring = 'The user DOMAIN\userid connected on port Mdm15 on 08/23/2002 at 07:25am and disconnected on
08/23/2002 at 07:27am. The user was active for 2 minutes 23 seconds. 78809 bytes were sent and 50675 bytes were received. The port speed was 49300.'
set @length = len(@mystring)
--print UserID
set @len1 = charindex('user',@mystring,1)
set @len2 = charindex('connected',@mystring,@len1)
print 'UserID:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'user','')))
--print Port Number
set @len1 = charindex('port',@mystring,1)
set @len2 = charindex('on',@mystring,(@len1))
print 'Port Number:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'port','')))
--Print Duration
set @len1 = charindex('user was active for ',@mystring,1)
set @len2 = charindex('.',@mystring,(@len1))
print 'Duration:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'user was active for','')))
--Print Bytes Sent
set @len1 = charindex('. ',@mystring,@len1)
set @len2 = charindex(' bytes',@mystring,(@len1))
print 'Bytes Sent:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'. ','')))
--Print Bytes Received
set @len1 = charindex('were sent and ',@mystring,@len1)
set @len2 = charindex(' bytes',@mystring,(@len1))
print 'Bytes Rcv:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1-1),'were sent and','')))
--Print Port Speed
set @len1 = charindex('port speed was',@mystring,@len1)
set @len2 = charindex('.',@mystring,(@len1))
print 'Port Speed:' + rtrim(ltrim(replace(substring(@mystring,@len1,@len2-@len1),'port speed was','')))
=====================================================
The above code returns the necessary values and now I need to insert these into a new table along with a few other columns from the event dump (date, time, servername). I've heard of using cursors to aid in the extraction and insert, but most forum entries advise not to use cursors for fear of performance degradation issues. Any thoughts?? Any help or script notes would be very appreciated
TIA
-Greg