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'
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.
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.
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.
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'
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With