Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I search stored procedure results?

Let's say I have a stored procedure which returns a large set of data. Can I write another query to filter the result of stored procedure?

For example:

select * from
EXEC xp_readerrorlog
where LogDate = '2011-02-15'
like image 760
Hammad Khan Avatar asked Feb 21 '12 13:02

Hammad Khan


People also ask

How do you query the results of a stored procedure?

The only way to work with the results of a stored procedure in T-SQL is to use the INSERT INTO ... EXEC syntax. That gives you the option of inserting into a temp table or a table variable and from there selecting the data you need. That requires knowing the table definition.

How do I view stored procedure results in SQL Server?

To view the definition a procedure in Object Explorer In Object Explorer, connect to an instance of Database Engine and then expand that instance. Expand Databases, expand the database in which the procedure belongs, and then expand Programmability.

How do I find a list of Stored Procedures in a database?

View the list of stored procedure in a database using a query. To view the list of the stored procedure, you can query the information_schema. routines table. It contains the list of the stored procedure and stored functions created on the database.


2 Answers

You would need to first insert the results of the stored procedure on a table, and then query those results.

create table #result (LogDate datetime, ProcessInfo varchar(20),Text text)

INSERT INTO #Result
EXEC xp_readerrorlog

SELECT *
FROM #Result
WHERE datepart(yy,LogDate) = '2012'
like image 53
Lamak Avatar answered Oct 06 '22 17:10

Lamak


Does returning the error log for just an entire day make the result any more useful? I think it will still be full of useless entries. If you're looking for specific events, why not use one of the filter parameters for xp_readerrorlog? The following wil return all rows in the current log that contain the string 'fail':

EXEC xp_readerrorlog 0, 1, 'fail';
like image 44
Aaron Bertrand Avatar answered Oct 06 '22 18:10

Aaron Bertrand