How to copy files from one folder to another folder using SQL Server?
In this article I'm going to explain how to transfer files from one location to another location using sql server.
In this article I'm going to explain how to transfer files from one location to another location using sql server.
By using xp_cmdshell command we can transfer files from one location to another location in sql server.
Herewith I have given one example to transfer files from one location to another location.
Declare @FileCopy varchar(Max)
DECLARE @FileName varchar(Max),@SourceFileName varchar(max)
Declare @DestinationFolderPath varchar(Max)
set @DestinationFolderPath = 'D:\TargetFolderName'
Set @SourceFileName = 'C:\SourceFolderName\filename.extension'
SET @FileCopy = ' COPY /Y ' + @SourceFileName + ' /B ' + @DestinationFolderPath
print @FileCopy
EXEC master..xp_cmdshell @FileCopy
If path is invalid then you will get output like this
Output:-
The system cannot find the path specified.
NULL