This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing the script for checking the existence of a file in SQL Server.
While exporting or reading the data from a file, we should check the existence of a file in our code of SQL Server.
Using xp_fileexist stored procedure, we can easily check this.
SQL Server: xp_cmdshell and BCP to export table data in a Text File
Check the below sample:
I created a sample file in this ‘D:\dbrnd.txt’ location.
1 2 3 4 5 6 7 8 9 10 |
DECLARE @IsFileExists INT EXEC Master.dbo.xp_fileexist 'D:\dbrnd.txt', @IsFileExists OUT IF @IsFileExists = 1 BEGIN PRINT 'File Exists...' END ELSE BEGIN PRINT 'File Does not Exists...' END |
Leave a Reply