Can I search stored procedure results?

ε祈祈猫儿з 提交于 2019-12-30 08:13:08

问题


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'

回答1:


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'



回答2:


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';



回答3:


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.




回答4:


You can copy output from sp to temporaty table.

insert into #temp
EXEC xp_readerrorlog

and then use where clause with the temp table




回答5:


or you can make a Table-valued Function



来源:https://stackoverflow.com/questions/9378533/can-i-search-stored-procedure-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!