understood ... what I forgot to mention is that some entries contain only "xx seconds" if that's all the time the user was connected. To catch these I added a CASE statement, and that's probably where it's messing-up. Here's a mock layout I've been working with:
1)
--declare string variables
declare @mystring varchar(1000)
declare @durstring 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.'
2)
--grab the time duration string
set @len1 = charindex('user was active for ',@mystring,1)
set @len2 = charindex('.',@mystring,(@len1))
set @durstring = replace(substring(@mystring,@len1,@len2-@len1),'user was active for ','')
3)
print 'Duration:' + CASE WHEN @durstring LIKE 'minutes' THEN
Cast(Left(@durstring,charindex('minutes',@durstring)-1) AS Numeric) * 60
+ Cast(substring(@durstring,charindex('minutes',@durstring)+8,2) AS Numeric)
ELSE
-- no minutes in string ... just seconds
Cast(substring(@durstring,charindex('seconds',@durstring)+8,2) AS Numeric)
END
I omitted the code that extracts several other values (port speed, date, time etc), but those are working fine. This is the one that causes issues right now.
thanks again Terry