SET
QUOTED_IDENTIFIER
ON
GO
SET
ANSI_NULLS
ON
GO
/*
select * FROM master..sysprocesses where hostprocess = 3368 order by cpu desc
master..xp_cmdshell 'tasklist /v'
*/
--
ALTER a splite function
Create
function
F_split_V2(
@S
nvarchar
(
4000
),
@i
int
)
returns
nvarchar
(
100
)
as
begin
if
@i
=
1
--
Image_name
begin
if
patindex
(
'
%.exe%
'
,
@s
)
=
0
set
@s
=
rtrim
(
left
(
@s
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
))
else
set
@s
=
rtrim
(
left
(
@s
,
patindex
(
'
%.exe%
'
,
@s
)
+
4
))
end
else
if
@i
=
2
--
Pid
begin
if
patindex
(
'
%.exe%
'
,
@s
)
=
0
set
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
else
set
@s
=
ltrim
(
substring
(
@s
,
patindex
(
'
%.exe%
'
,
@s
)
+
4
,
len
(
@s
)))
select
@s
=
rtrim
(
left
(
@s
,
patindex
(
'
%[^0-9]%
'
,
@s
)
-
1
))
end
else
if
@i
=
3
--
Session_name
begin
if
patindex
(
'
%.exe%
'
,
@s
)
=
0
set
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
else
set
@s
=
ltrim
(
substring
(
@s
,
patindex
(
'
%.exe%
'
,
@s
)
+
4
,
len
(
@s
)))
select
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[^0-9]%
'
,
@s
)
-
1
,
''
),
@s
=
rtrim
(
left
(
@s
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
))
end
else
if
@i
=
4
--
Session#
begin
if
patindex
(
'
%.exe%
'
,
@s
)
=
0
set
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
else
set
@s
=
ltrim
(
substring
(
@s
,
patindex
(
'
%.exe%
'
,
@s
)
+
4
,
len
(
@s
)))
select
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[^0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
rtrim
(
left
(
@s
,
patindex
(
'
% %
'
,
@s
)
-
1
))
end
else
if
@i
=
5
--
memory
begin
if
patindex
(
'
%.exe%
'
,
@s
)
=
0
set
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
else
set
@s
=
ltrim
(
substring
(
@s
,
patindex
(
'
%.exe%
'
,
@s
)
+
4
,
len
(
@s
)))
select
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[^0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[1-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
rtrim
(
left
(
@s
,
patindex
(
'
%k%
'
,
@s
)
-
1
))
end
else
if
@i
=
6
--
user_name
select
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[^0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
stuff
(
@s
,
1
,
patindex
(
'
%[1-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
rtrim
(
substring
(
@s
,
patindex
(
'
%\%
'
,
@s
)
+
1
,
18
))
else
if
@i
=
7
--
cup_time
select
@s
=
substring
(
@s
,
patindex
(
'
%[0-9]:[0-9][0-9]:[0-9][0-9]%
'
,
@s
),
8
)
else
select
@s
=right
(
@s
,
charindex
(
'
'
,
reverse
(
@s
),
3
)
-
1
)
return
@s
end
GO
SET
QUOTED_IDENTIFIER
OFF
GO
SET
ANSI_NULLS
ON
GO