Home >Database >Mysql Tutorial >How Can I Check for File Existence in SQL Server Using a Function?
Check for File Existence in SQL Server Using a Function
To determine if a file exists on your local machine using SQL Server, you can employ the following approach:
CREATE FUNCTION dbo.fn_FileExists(@path varchar(512)) RETURNS BIT AS BEGIN DECLARE @result INT EXEC master.dbo.xp_fileexist @path, @result OUTPUT RETURN cast(@result as bit) END; GO
dbo.fn_FileExists(filepath)
SELECT * FROM dbo.MyTable WHERE IsExists = 1;
SELECT id, filename, dbo.fn_FileExists(filename) AS IsExists FROM dbo.MyTable;
The above is the detailed content of How Can I Check for File Existence in SQL Server Using a Function?. For more information, please follow other related articles on the PHP Chinese website!