Stored Procedure to check if a file exists or not.

  SQL Advanced

Returns 1 if exists and 0 if it does not.

 

Code:

USE [DATABASE]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Bruno Figueiredo
-- Company: AirTistic.net 
-- =============================================
CREATE PROCEDURE [dbo].[MTS_CheckFile]
@FILE_COMPLETE_PATH VARCHAR(500)
AS
BEGIN
SET NOCOUNT ON;

DECLARE @isExists INT

exec master.dbo.xp_fileexist @FILE_COMPLETE_PATH, @isExists OUTPUT
SELECT case @isExists when 1 then '1' else '0' end as isExists

END