|
Execute the following Microsoft SQL Server Transact-SQL (T-SQL) script in Management Studio (SSMS) Query Editor, SQLCMD or other client software
Editor to create a today's date specific filename
and apply it in a copy command:
USE AdventureWorks
GO
DECLARE @SQLCommand varchar(1000)
DECLARE @SourcePath varchar(100), @DestinationPath varchar(100)
DECLARE @FileName varchar(40), @DateSuffix char(20), @Extention
char(4)
SET @SourcePath = 'e:\data\import\'
SET @DestinationPath = 'e:\data\import\archive\'
SET @FileName = 'DailyFinanceFeed'
SET @Extention = '.txt'
SET @DateSuffix = RTRIM(REPLACE('-'+CONVERT(char(8),GETDATE(),1)+@Extention,'/','-'))
SET @SQLCommand = 'Copy '+@SourcePath+@FileName+@Extention+'
'+@DestinationPath+@FileName+@DateSuffix
PRINT @SQLCommand
EXEC master..xp_cmdshell @SQLCommand, NO_OUTPUT
|