Solved

xp_cmdshell copy file and append date to name

Posted on 2003-10-28
6
1,961 Views
Last Modified: 2007-12-19
I am trying to copy a file and append the date to the name - I do not want the time, date only - using the xp_cmdshell (unless there is a better way) - I cannot get the date concatentaion for the life of me?

declare @rc int, @varDate sysname
SET @varDate = getdate()
exec @rc = master..xp_cmdshell 'copy c:\test\test_error_log.txt c:\test\test_error_log_"+@varDate+".txt', no_output
select @rc
0
Comment
Question by:tbaseflug
  • 3
  • 3
6 Comments
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 9636178
Too many Open questions.
0
 

Author Comment

by:tbaseflug
ID: 9636184
I know - I am making the effort today to go and close some of them out - have been out of town for the past few months and have not had chance for cleanup
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 9636232
In that case, maybe try something like this:


declare @rc int
DECLARE @cmd VARCHAR(500)
SET @cmd = 'copy c:\test\test_error_log.txt c:\test\test_error_log_' +
      CONVERT(CHAR(8), GETDATE(), 112) + '.txt'
exec @rc = master..xp_cmdshell @cmd, NO_OUTPUT
select @rc

This will put the date in YYYYMMDD format; if you need another format, just let me know :-)
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:tbaseflug
ID: 9636245
wow - works great!  How would I format the date to something like:
mm_dd_yy
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 125 total points
ID: 9636317
REPLACE(CONVERT(CHAR(8), GETDATE(), 1), '/', '_')
0
 

Author Comment

by:tbaseflug
ID: 9636342
Awesome!  Thanks!!!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
find SQL job run average duration 24 54
Database maintenance 36 100
SQL Syntax 6 39
UPDATE JOIN multiple tables 5 19
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question