从存储过程中检索结果非常困难。基本上,您必须创建一个与其确切列输出匹配的表,并将其insert ... exec
放入其中。where
在子句中根本没有机会这样做。
但是,您可以在 a 中循环while
,然后他们将结果泵入表格中。例如:
set nocount on
if OBJECT_ID('tempdb..#TempFileList') is not null
drop table #TempFileList
create table #TempFileList (file_name nvarchar(250), file_exist bit)
insert #TempFileList (file_name) values ('c:\windows\win.ini')
insert #TempFileList (file_name) values ('c:\somefile.txt')
if OBJECT_ID('tempdb..#TempFileResult') is not null
drop table #TempFileResult
create table #TempFileResult (File_exists int, File_directory int,parent_dir int)
declare c cursor local fast_forward for select file_name from #TempFileList
open c
declare @file_name nvarchar(250)
fetch from c into @file_name
while @@FETCH_STATUS = 0
begin
delete from #TempFileResult
insert into #TempFileResult exec Master.dbo.xp_fileexist @file_name
update #TempFileList
set file_exist = (select file_exists from #TempFileResult)
where file_name = @file_name
fetch from c into @file_name
end
close c
deallocate c
select * from #TempFileList
在我的系统上,打印:
file_name file_exist
c:\windows\win.ini 1
c:\somefile.txt 0