ストアド プロシージャから結果を取得するのは非常に困難です。基本的に、正確な列出力とそれに一致するテーブルを作成する必要がありますinsert ... exec
。where
句でそれを行う機会はまったくありません。
ただし、 をループして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