代码之家  ›  专栏  ›  技术社区  ›  Wael Dalloul

我可以使用order by对存储过程结果进行排序吗?

  •  20
  • Wael Dalloul  · 技术社区  · 15 年前

    简单地说,我有一个SQL语句:

    EXEC xp_cmdshell 'tasklist' 
    

    我们能用以下方法订购或筛选结果吗? order by where ?

    谢谢,

    3 回复  |  直到 15 年前
        1
  •  14
  •   Community Mohan Dere    9 年前

    您需要首先将结果输出到一个临时表中。这应该告诉你怎么做

    Insert results of a stored procedure into a temporary table

        2
  •  9
  •   Wael Dalloul    15 年前

    我查看了Jamietre链接,这是完整的答案:

    Create table  #MyTempTable
    (output varchar(max))
    
    INSERT INTO #MyTempTable
    EXEC xp_cmdshell 'tasklist' 
    
    select * from #MyTempTable where output like 'ie%' order by output 
    

    谢谢大家…

        3
  •  2
  •   chuck taylor    15 年前

    不是直接的。您可以将exec插入临时表或表变量,然后对其进行排序。