写个函数折分呀或
动态方式 换行内的的特定字符换成'','' 最后加 union all
执行串

解决方案 »

  1.   

    不是很明白你的意思 如果你是想把下面的结果(也就是存储过程的结果)保存到另外一张表的话
    可以先建立一张表tabnew 然后 insert into tabnew exec procname @param1....
      

  2.   

    create   table   #temp 
    ( id   int   identity(1,1)   not   null ,Proc_info   nvarchar(4000) null ) 
    insert   into   #temp(Proc_info) 
    exec   master..xp_cmdshell   'tasklist' go
    --删除非进程数据
    delete  #temp where Proc_info is null or Proc_info like '%=========================%' or ID=2--  图像名                    PID 会话名           会话#       内存使用 go
    --建个函数分拆:
    create function F_split(@S nvarchar(4000),@i int)
    returns nvarchar(100)
    as
    begin
    if @i=1
    set @s=rtrim(left(@s,patindex('%[0-9]%',@s)-1))
    else if @i=2
    select @s=stuff(@s,1,patindex('%[0-9]%',@s)-1,''),
    @s=rtrim(left(@s,patindex('%[^0-9]%',@s)-1))
    else if @i=3
    select @s=stuff(@s,1,patindex('%[0-9]%',@s)-1,''),@s=stuff(@s,1,patindex('%[^0-9]%',@s)-1,''),
    @s=rtrim(left(@s,patindex('%[0-9]%',@s)-1))
    else if @i=4
    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=left(@s,patindex('% %',@s)-1)
    else 
    select @s=right(@s,charindex(' ',reverse(@s),3)-1)
    return @s
    end
    goselect 
    ID,
    dbo.F_split(Proc_info,1) as 图像名,
    dbo.F_split(Proc_info,2)as PID,
    dbo.F_split(Proc_info,3) as 会话名,
    dbo.F_split(Proc_info,4) as 会话#,
    dbo.F_split(Proc_info,5) as 内存使用
    from 
    #temp--生成格式
    /*
    4 System Idle Process 0  Console 0 16 K
    5 System 4  Console 0 32 K
    6 smss.exe 520  Console 0 52 K
    7 csrss.exe 584  Console 0 6,412 K
    8 winlogon.exe 608  Console 0 5,092 K
    9 services.exe 652  Console 0 1,028 K
    10 lsass.exe 676  Console 0 1,312 K
    11 svchost.exe 836  Console 0 1,440 K
    12 svchost.exe 884  Console 0 1,372 K*/
      

  3.   

    就是大虾roy_88给我的效果,谢谢各位的热心恢复。