April 12, 2010 at 8:04 am
Hi,
i've this script that insert all "tasklist" into a table.
i want that the Image Name will be in one column and the Mem Usage will be in another column but the Image Name next to the Mem Usage.
How i do that?
THX
declare @tasklist table (taskname nvarchar (500))
insert into @tasklist
exec xp_cmdshell 'tasklist /fo list'
delete from @tasklist where taskname IS NULL or taskname like 'Session Name:%' or taskname like 'Session#%' or taskname like 'PID:%'
select * from @tasklist
April 12, 2010 at 10:05 am
You should probably just leave the default format and pick out the columns you need:
DECLARE @tasklist TABLE (taskname NVARCHAR (500))
INSERT INTO @tasklist
EXEC xp_cmdshell 'tasklist'
DELETE FROM @tasklist WHERE taskname IS NULL OR taskname = 'Image Name' OR taskname LIKE '%Mem Usage' OR taskname LIKE '===%'
SELECT
LEFT(taskname,25) AS 'Image Name'
,LTRIM(RTRIM(RIGHT(taskname,12))) AS 'Mem Usage'
FROM
@tasklist
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply