Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I Use Order by to sort Stored Procedure results?

Simply, I have this SQL statment:

EXEC xp_cmdshell 'tasklist'  

can we order or filter the results by using order by or where?

Thanks,

like image 518
Wael Dalloul Avatar asked Oct 26 '10 12:10

Wael Dalloul


People also ask

Can we use order by in SQL function?

The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns. By default ORDER BY sorts the data in ascending order. We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.

Do stored procedures execute in order?

from inside the procedure, the commands run in the order you created them in, and there is no way for the third to execute before the previous commands complete.

Which is better view or stored procedure?

A view is essentially a saved SQL statement. Therefore, I would say that in general, a stored procedure will be likely to be faster than a view IF the SQL statement for each is the same, and IF the SQL statement can benefit from optimizations. Otherwise, in general, they would be similar in performance.

Can I use a stored procedure in a select statement?

We can not directly use stored procedures in a SELECT statement.


2 Answers

I checked jamietre link, and this is the complete answer:

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

Thanks for all...

like image 112
Wael Dalloul Avatar answered Sep 24 '22 05:09

Wael Dalloul


You need to output the results into a temporary table first. This should show you how to do it

Insert results of a stored procedure into a temporary table

like image 26
Jamie Treworgy Avatar answered Sep 24 '22 05:09

Jamie Treworgy