SQL server 2008: Copy a file and rename it
sql-server, sql-server-2008, t-sql
Solution
You can use xp_cmdshell to run any DOS commands you like, e.g.
declare @cmdstring varchar(1000)
set @cmdstring = 'copy \\myServer\Admin\temp\testtemp.txt \\myServer\Admin\temp\Copytesttemp.txt'
exec master..xp_cmdshell @cmdstring
Just make sure xp_cmdshell is enabled on your installation.
Problem
I have a file inside a directory `\\myServer\Admin\temp\testtemp.txt` I need to write a TSQL to - Search for `testtemp.txt` file. - If exists, create a copy of it and rename it to `Copytesttemp.txt` If there's `testtemp.txt` already in the above directory like this ``` \\abcd\Admin\temp\Copytesttemp.txt ``` then delete it and recreate `Copytesttemp.txt` How do I achieve it? Thanks.