Reputation: 17354
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'
Upvotes: 10
Views: 10981
Reputation: 11
this can not be done in SQL Server unless you create a temp table with all the Columns and Column DataTypes
which can be annoying if you deal with a large number of columns and you don't know the table by hand, but you just want a few columns and filter the results
So I have found a workaround using MS Access you can create a pass-through query in MS Access
see: https://support.microsoft.com/en-us/office/create-a-pass-through-query-b775ac23-8a6b-49b2-82e2-6dac62532a42
and there you can just pass the EXEC xp_readerrorlog
and name the pass-through query as Q_readerrorlog
and you can then create another local Query in MS Access with the SQL: as
select * from
Q_readerrorlog
where LogDate = '2011-02-15'
Upvotes: 1
Reputation: 70648
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'
Upvotes: 17
Reputation: 280351
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';
Upvotes: 1
Reputation: 8333
You can copy output from sp to temporaty table.
insert into #temp
EXEC xp_readerrorlog
and then use where clause with the temp table
Upvotes: 0
Reputation: 12804
You can't make it part of a query, BUT you could insert the resulting data into a temp table or table variable and then use that for your query.
Upvotes: 1