Sql server 2008 xp\u文件存在,如果存在
我目前正在尝试创建一个存储过程来检查文件是否存在,如果存在,那么它将运行更多的代码,如果没有。它停了 所以我使用的是Sql server 2008 xp\u文件存在,如果存在,sql-server-2008,stored-procedures,Sql Server 2008,Stored Procedures,我目前正在尝试创建一个存储过程来检查文件是否存在,如果存在,那么它将运行更多的代码,如果没有。它停了 所以我使用的是exec master..xp\u fileexist@FileName 这是回报 File Exists| File is a Directory| Parent Directory Exists 1| 0| 1 我无法理解将存储的proc放入IF EXISTS语句的语法或设置 IF EXISTS (
exec master..xp\u fileexist@FileName
这是回报
File Exists| File is a Directory| Parent Directory Exists
1| 0| 1
我无法理解将存储的proc放入IF EXISTS
语句的语法或设置
IF EXISTS (
exec master..xp_fileexist @FileName
)
BEGIN
select 'File is there'
END
ELSE
BEGIN
select 'File is not there'
END
上述方法行不通,有人能帮我找到正确的方法吗?我能想到的最佳方法是使用
OPENROWSET
并用存储过程的结果填充临时表。但是传递一个参数很棘手,但是这个链接应该让你朝着正确的方向开始
填充表后,只需使用普通的
IF EXISTS
查询我能想到的最佳方法是使用OPENROWSET
并用存储过程的结果填充临时表。但是传递一个参数很棘手,但是这个链接应该让你朝着正确的方向开始
填充表后,只需使用普通的
IF EXISTS
查询即可xp\u fileexists
始终返回结果
因此,您不希望检查结果是否存在,而是希望检查过程调用的结果
要获得过程调用的结果,可以使用insert。。。exec
construct
declare @t table (fileexists bit, fileisdirectory bit, parentdirectoryexists bit)
insert @t
exec master..xp_fileexist 'c:\windows\explorer.exe'
if (exists (select * from @t where fileexists=1))
begin
select 'file is there'
end
xp\u fileexists
始终返回结果
因此,您不希望检查结果是否存在,而是希望检查过程调用的结果
要获得过程调用的结果,可以使用insert。。。exec
construct
declare @t table (fileexists bit, fileisdirectory bit, parentdirectoryexists bit)
insert @t
exec master..xp_fileexist 'c:\windows\explorer.exe'
if (exists (select * from @t where fileexists=1))
begin
select 'file is there'
end
您可以这样做:
declare @result as int
declare @path as nvarchar(50)
--set your path
set @path= 'C:\'
EXEC master.dbo.xp_fileexist @path, @result OUTPUT
if @result=1
print 'found'
else
print 'not found'
您可以这样做:
declare @result as int
declare @path as nvarchar(50)
--set your path
set @path= 'C:\'
EXEC master.dbo.xp_fileexist @path, @result OUTPUT
if @result=1
print 'found'
else
print 'not found'
遵循以下步骤:
MyPc\Sqlexpress
)MyPc\Sqlexpress
)